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
impl ElicitClient
Sourcepub fn new(peer: Arc<Peer<RoleClient>>) -> Self
pub fn new(peer: Arc<Peer<RoleClient>>) -> Self
Create a new client wrapper from an RMCP peer.
Sourcepub fn peer(&self) -> &Peer<RoleClient>
pub fn peer(&self) -> &Peer<RoleClient>
Get the underlying RMCP peer for making tool calls.
Sourcepub fn with_style<T: Elicitation + 'static, S: ElicitationStyle>(
&self,
style: S,
) -> Self
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);Sourcepub fn style_or_default<T: Elicitation + 'static>(&self) -> T::Stylewhere
T::Style: ElicitationStyle,
pub fn style_or_default<T: Elicitation + 'static>(&self) -> T::Stylewhere
T::Style: ElicitationStyle,
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>();Sourcepub async fn style_or_elicit<T: Elicitation + 'static>(
&self,
) -> ElicitResult<T::Style>where
T::Style: ElicitationStyle,
pub async fn style_or_elicit<T: Elicitation + 'static>(
&self,
) -> ElicitResult<T::Style>where
T::Style: ElicitationStyle,
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?;Sourcepub async fn current_style<T: Elicitation + 'static>(
&self,
) -> ElicitResult<T::Style>
pub async fn current_style<T: Elicitation + 'static>( &self, ) -> ElicitResult<T::Style>
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.