Skip to main content

ElicitClient

Struct ElicitClient 

Source
pub struct ElicitClient { /* private fields */ }
Expand description

Client wrapper that carries style context.

Wraps an RMCP peer and maintains style selections for different types. Each type can have its own style, allowing nested types to use different styles independently.

Users can provide custom style types for any type by implementing ElicitationStyle and calling with_style.

§Example

use elicitation::{ElicitClient, ElicitationStyle, Elicitation};

// Define custom style for i32
#[derive(Clone, Default)]
enum MyI32Style {
    #[default]
    Terse,
    Verbose
}

impl ElicitationStyle for MyI32Style {}

// Use it
let client = ElicitClient::new(peer);
let styled = client.with_style::<i32, _>(MyI32Style::Verbose);
let age = i32::elicit(&styled).await?;

Implementations§

Source§

impl ElicitClient

Source

pub fn new(peer: Arc<Peer<RoleClient>>) -> Self

Create a new client wrapper from an RMCP peer.

Source

pub fn peer(&self) -> &Peer<RoleClient>

Get the underlying RMCP peer for making tool calls.

Source

pub fn with_style<T: Elicitation + 'static, S: ElicitationStyle>( &self, style: S, ) -> Self

Create a new client with a custom style for a specific type.

Accepts any style type that implements ElicitationStyle, allowing users to define custom styles for built-in types.

Returns a new ElicitClient with the style added to the context. The original client is unchanged.

§Example
// Use default style
let client = client.with_style::<Config, _>(ConfigStyle::default());

// Use custom style for i32
let client = client.with_style::<i32, _>(MyI32Style::Verbose);
Source

pub fn style_or_default<T: Elicitation + 'static>(&self) -> T::Style

Get the current style for a type, or use default if not set.

This method checks if a custom style was set via with_style(). If a style was set, it returns that style. Otherwise, it returns the default style for the type.

§Example
// Get style - uses custom if set, default otherwise
let style = client.style_or_default::<Config>();
Source

pub async fn style_or_elicit<T: Elicitation + 'static>( &self, ) -> ElicitResult<T::Style>

Get the current style for a type, eliciting if not set.

This method checks if a custom style was set via with_style(). If a style was set, it returns that style. Otherwise, it elicits the style from the user.

This enables “auto-selection”: styles are only elicited when needed.

§Example
// Get style - uses custom if set, otherwise asks user
let style = client.style_or_elicit::<Config>().await?;
Source

pub async fn current_style<T: Elicitation + 'static>( &self, ) -> ElicitResult<T::Style>
where T::Style: Clone + Send + Sync + 'static,

Get the current style for a type, or use the default.

If a custom style has been set via with_style(), returns that. Otherwise, returns T::Style::default() as fallback.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Refines<T> for T
where T: 'static,