Skip to main content

elicitation/
elicitation_style.rs

1//! ElicitationStyle trait and infrastructure.
2//!
3//! This module defines the trait that all style enums must implement,
4//! enabling users to define custom styles for any type.
5
6/// Trait for elicitation style types.
7///
8/// Style types define how a type should be elicited. Each type has a default
9/// style, but users can define custom styles and apply them at runtime.
10///
11/// # Requirements
12///
13/// - `Clone`: Styles must be cloneable for context storage
14/// - `Send + Sync`: Styles must be thread-safe
15/// - `Default`: Provides fallback when no style is specified
16/// - `'static`: Required for type-erased storage
17///
18/// # Example
19///
20/// ```rust,ignore
21/// use elicitation::{ElicitationStyle, Elicitation, ElicitClient, ElicitResult};
22///
23/// // Define a custom style for i32
24/// #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
25/// pub enum MyI32Style {
26///     #[default]
27///     Terse,
28///     Verbose,
29/// }
30///
31/// impl ElicitationStyle for MyI32Style {}
32///
33/// impl Elicitation for MyI32Style {
34///     type Style = Self;
35///     
36///     async fn elicit<C: ElicitCommunicator>(communicator: &C) -> ElicitResult<Self> {
37///         // Implement selection logic
38///         Ok(Self::default())
39///     }
40/// }
41///
42/// // Use it:
43/// let client = base_client.with_style::<i32, _>(MyI32Style::Verbose);
44/// let value = i32::elicit(&client).await?;
45/// ```
46pub trait ElicitationStyle: Clone + Send + Sync + Default + 'static {
47    // Marker trait - no methods required
48    // The trait bounds provide everything the system needs
49}
50
51/// Blanket implementation for types that satisfy the requirements.
52///
53/// This automatically implements ElicitationStyle for any type that meets
54/// the trait bounds, making it easy to define custom styles.
55impl<T> ElicitationStyle for T where T: Clone + Send + Sync + Default + 'static {}