pub struct AnyProjector { /* private fields */ }Expand description
A type-erased ConversationProjector for dynamic dispatch.
Wraps any concrete projector so it can be stored in trait objects, passed across module boundaries, or held in collections alongside projectors with different output types.
§Example
use toolpath_convo::{ConversationView, ConversationProjector, Result};
use toolpath_convo::project::AnyProjector;
use std::collections::HashMap;
struct TurnCounter;
impl ConversationProjector for TurnCounter {
type Output = usize;
fn project(&self, view: &ConversationView) -> Result<usize> {
Ok(view.turns.len())
}
}
let view = ConversationView {
id: "s1".into(),
started_at: None,
last_activity: None,
turns: vec![],
total_usage: None,
provider_id: None,
files_changed: vec![],
session_ids: vec![],
events: vec![],
};
let projector = AnyProjector::new(TurnCounter);
let count = projector.project_as::<usize>(&view).unwrap();
assert_eq!(count, 0);Implementations§
Source§impl AnyProjector
impl AnyProjector
Sourcepub fn new<P>(projector: P) -> Self
pub fn new<P>(projector: P) -> Self
Wrap a concrete ConversationProjector for type-erased dispatch.
Sourcepub fn project(&self, view: &ConversationView) -> Result<Box<dyn Any>>
pub fn project(&self, view: &ConversationView) -> Result<Box<dyn Any>>
Project view and return the result as Box<dyn Any>.
Use project_as when the concrete output
type is known at the call site.
Sourcepub fn project_as<T: 'static>(&self, view: &ConversationView) -> Result<T>
pub fn project_as<T: 'static>(&self, view: &ConversationView) -> Result<T>
Project view and downcast the result to T.
Returns Err(ConvoError::Provider(...)) if the downcast fails, which
means T does not match the projector’s actual Output type.
Auto Trait Implementations§
impl Freeze for AnyProjector
impl !RefUnwindSafe for AnyProjector
impl Send for AnyProjector
impl Sync for AnyProjector
impl Unpin for AnyProjector
impl UnsafeUnpin for AnyProjector
impl !UnwindSafe for AnyProjector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more