pub struct MaterializeResult<T> {
pub data: T,
pub usage: Option<TokenUsage>,
}Expand description
Result of a materialize call, containing both the data and optional usage information.
This struct wraps the deserialized data along with token usage metadata from the final successful LLM API call.
§Example
use rstructor::{LLMClient, OpenAIClient, Instructor};
use serde::{Serialize, Deserialize};
#[derive(Instructor, Serialize, Deserialize)]
struct Person { name: String, age: u8 }
let client = OpenAIClient::from_env()?;
let result = client.materialize_with_metadata::<Person>("Describe a person").await?;
// Access the data directly
println!("Name: {}", result.data.name);
// Check token usage
if let Some(usage) = result.usage {
println!("Used {} total tokens", usage.total_tokens());
}Fields§
§data: TThe deserialized data
usage: Option<TokenUsage>Token usage information (if available from the provider)
Implementations§
Source§impl<T> MaterializeResult<T>
impl<T> MaterializeResult<T>
Sourcepub fn new(data: T, usage: Option<TokenUsage>) -> Self
pub fn new(data: T, usage: Option<TokenUsage>) -> Self
Create a new MaterializeResult with data and usage
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> MaterializeResult<U>
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> MaterializeResult<U>
Map the data to a new type
Trait Implementations§
Source§impl<T: Clone> Clone for MaterializeResult<T>
impl<T: Clone> Clone for MaterializeResult<T>
Source§fn clone(&self) -> MaterializeResult<T>
fn clone(&self) -> MaterializeResult<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for MaterializeResult<T>where
T: Freeze,
impl<T> RefUnwindSafe for MaterializeResult<T>where
T: RefUnwindSafe,
impl<T> Send for MaterializeResult<T>where
T: Send,
impl<T> Sync for MaterializeResult<T>where
T: Sync,
impl<T> Unpin for MaterializeResult<T>where
T: Unpin,
impl<T> UnsafeUnpin for MaterializeResult<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for MaterializeResult<T>where
T: UnwindSafe,
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