pub struct GeneratedContent { /* private fields */ }Expand description
A piece of generated structured content.
Apple models structured generations as GeneratedContent; the Rust wrapper
stores the JSON value plus the metadata that Apple’s streaming API exposes.
Implementations§
Source§impl GeneratedContent
impl GeneratedContent
Sourcepub fn from_json_str(json: &str) -> Result<Self, FMError>
pub fn from_json_str(json: &str) -> Result<Self, FMError>
Parse a JSON string into generated content.
§Errors
Returns FMError::InvalidArgument if json is not valid JSON.
Sourcepub fn from_json_str_with_id(
json: &str,
generation_id: impl Into<Option<GenerationId>>,
) -> Result<Self, FMError>
pub fn from_json_str_with_id( json: &str, generation_id: impl Into<Option<GenerationId>>, ) -> Result<Self, FMError>
Parse a JSON string into generated content with an attached generation ID.
§Errors
Returns FMError::InvalidArgument if json is not valid JSON.
Sourcepub fn from_value<T>(value: T) -> Result<Self, FMError>where
T: Serialize,
pub fn from_value<T>(value: T) -> Result<Self, FMError>where
T: Serialize,
Convert a serializable Rust value into generated content.
§Errors
Returns FMError::InvalidArgument if value cannot be encoded as JSON.
Sourcepub fn from_value_with_id<T>(
value: T,
generation_id: impl Into<Option<GenerationId>>,
) -> Result<Self, FMError>where
T: Serialize,
pub fn from_value_with_id<T>(
value: T,
generation_id: impl Into<Option<GenerationId>>,
) -> Result<Self, FMError>where
T: Serialize,
Convert a serializable Rust value into generated content with an ID.
§Errors
Returns FMError::InvalidArgument if value cannot be encoded as JSON.
Sourcepub fn from_kind(kind: GeneratedContentKind) -> Result<Self, FMError>
pub fn from_kind(kind: GeneratedContentKind) -> Result<Self, FMError>
Build generated content from a GeneratedContentKind value.
§Errors
Returns FMError::InvalidArgument if the kind cannot be represented as valid JSON.
Sourcepub fn from_kind_with_id(
kind: GeneratedContentKind,
generation_id: impl Into<Option<GenerationId>>,
) -> Result<Self, FMError>
pub fn from_kind_with_id( kind: GeneratedContentKind, generation_id: impl Into<Option<GenerationId>>, ) -> Result<Self, FMError>
Build generated content from a GeneratedContentKind value with an ID.
§Errors
Returns FMError::InvalidArgument if the kind cannot be represented as valid JSON.
Sourcepub fn from_elements<T>(
elements: impl IntoIterator<Item = T>,
) -> Result<Self, FMError>where
T: ToGeneratedContent,
pub fn from_elements<T>(
elements: impl IntoIterator<Item = T>,
) -> Result<Self, FMError>where
T: ToGeneratedContent,
Sourcepub fn from_elements_with_id<T>(
elements: impl IntoIterator<Item = T>,
generation_id: impl Into<Option<GenerationId>>,
) -> Result<Self, FMError>where
T: ToGeneratedContent,
pub fn from_elements_with_id<T>(
elements: impl IntoIterator<Item = T>,
generation_id: impl Into<Option<GenerationId>>,
) -> Result<Self, FMError>where
T: ToGeneratedContent,
Sourcepub fn from_properties<K, V>(
properties: impl IntoIterator<Item = (K, V)>,
) -> Result<Self, FMError>
pub fn from_properties<K, V>( properties: impl IntoIterator<Item = (K, V)>, ) -> Result<Self, FMError>
Sourcepub fn from_properties_with_id<K, V>(
properties: impl IntoIterator<Item = (K, V)>,
generation_id: impl Into<Option<GenerationId>>,
) -> Result<Self, FMError>
pub fn from_properties_with_id<K, V>( properties: impl IntoIterator<Item = (K, V)>, generation_id: impl Into<Option<GenerationId>>, ) -> Result<Self, FMError>
Sourcepub fn from_properties_with<K, V, F>(
properties: impl IntoIterator<Item = (K, V)>,
generation_id: impl Into<Option<GenerationId>>,
combine: F,
) -> Result<Self, FMError>where
K: Into<String>,
V: ToGeneratedContent,
F: FnMut(GeneratedContent, GeneratedContent) -> Result<GeneratedContent, FMError>,
pub fn from_properties_with<K, V, F>(
properties: impl IntoIterator<Item = (K, V)>,
generation_id: impl Into<Option<GenerationId>>,
combine: F,
) -> Result<Self, FMError>where
K: Into<String>,
V: ToGeneratedContent,
F: FnMut(GeneratedContent, GeneratedContent) -> Result<GeneratedContent, FMError>,
Sourcepub fn into_raw_value(self) -> Value
pub fn into_raw_value(self) -> Value
Consume the content and return the underlying JSON value.
Sourcepub fn kind(&self) -> GeneratedContentKind
pub fn kind(&self) -> GeneratedContentKind
Return the typed content kind.
Sourcepub fn json_string(&self) -> Result<String, FMError>
pub fn json_string(&self) -> Result<String, FMError>
Serialize the content back to a compact JSON string.
§Errors
Returns FMError::Unknown if serialization fails.
Sourcepub fn json_string_pretty(&self) -> Result<String, FMError>
pub fn json_string_pretty(&self) -> Result<String, FMError>
Sourcepub fn value<T>(&self) -> Result<T, FMError>where
T: DeserializeOwned,
pub fn value<T>(&self) -> Result<T, FMError>where
T: DeserializeOwned,
Decode the content into a Rust value.
§Errors
Returns FMError::DecodingFailure if the JSON value does not match T.
Sourcepub fn value_for_property<T>(&self, property: &str) -> Result<T, FMError>where
T: DeserializeOwned,
pub fn value_for_property<T>(&self, property: &str) -> Result<T, FMError>where
T: DeserializeOwned,
Decode a named property from an object content value.
§Errors
Returns FMError::DecodingFailure if the value is not an object, the
property does not exist, or the property cannot be decoded as T.
Sourcepub const fn is_complete(&self) -> bool
pub const fn is_complete(&self) -> bool
Whether Apple’s structured stream reported this content as complete.
Sourcepub fn generation_id(&self) -> Option<&str>
pub fn generation_id(&self) -> Option<&str>
Apple’s opaque generation identifier, if one was attached.
Sourcepub fn generation_id_handle(&self) -> Option<&GenerationId>
pub fn generation_id_handle(&self) -> Option<&GenerationId>
Borrow the typed generation identifier handle, if one was attached.
Sourcepub fn with_generation_id(
self,
generation_id: impl Into<Option<GenerationId>>,
) -> Self
pub fn with_generation_id( self, generation_id: impl Into<Option<GenerationId>>, ) -> Self
Replace the attached generation identifier.
Trait Implementations§
Source§impl Clone for GeneratedContent
impl Clone for GeneratedContent
Source§fn clone(&self) -> GeneratedContent
fn clone(&self) -> GeneratedContent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GeneratedContent
impl Debug for GeneratedContent
Source§impl From<&str> for GeneratedContent
impl From<&str> for GeneratedContent
Source§impl From<GeneratedContent> for Instructions
impl From<GeneratedContent> for Instructions
Source§fn from(content: GeneratedContent) -> Self
fn from(content: GeneratedContent) -> Self
Source§impl From<GeneratedContent> for Prompt
impl From<GeneratedContent> for Prompt
Source§fn from(content: GeneratedContent) -> Self
fn from(content: GeneratedContent) -> Self
Source§impl From<GeneratedContent> for ToolOutput
impl From<GeneratedContent> for ToolOutput
Source§fn from(value: GeneratedContent) -> Self
fn from(value: GeneratedContent) -> Self
Source§impl From<GeneratedContent> for Value
impl From<GeneratedContent> for Value
Source§fn from(value: GeneratedContent) -> Self
fn from(value: GeneratedContent) -> Self
Source§impl From<String> for GeneratedContent
impl From<String> for GeneratedContent
Source§impl<T> From<Vec<T>> for GeneratedContentwhere
T: Into<GeneratedContent>,
impl<T> From<Vec<T>> for GeneratedContentwhere
T: Into<GeneratedContent>,
Source§impl From<bool> for GeneratedContent
impl From<bool> for GeneratedContent
Source§impl From<f32> for GeneratedContent
impl From<f32> for GeneratedContent
Source§impl From<f64> for GeneratedContent
impl From<f64> for GeneratedContent
Source§impl From<i8> for GeneratedContent
impl From<i8> for GeneratedContent
Source§impl From<i16> for GeneratedContent
impl From<i16> for GeneratedContent
Source§impl From<i32> for GeneratedContent
impl From<i32> for GeneratedContent
Source§impl From<i64> for GeneratedContent
impl From<i64> for GeneratedContent
Source§impl From<u8> for GeneratedContent
impl From<u8> for GeneratedContent
Source§impl From<u16> for GeneratedContent
impl From<u16> for GeneratedContent
Source§impl From<u32> for GeneratedContent
impl From<u32> for GeneratedContent
Source§impl From<u64> for GeneratedContent
impl From<u64> for GeneratedContent
Source§impl FromGeneratedContent for GeneratedContent
impl FromGeneratedContent for GeneratedContent
Source§fn from_generated_content(content: &GeneratedContent) -> Result<Self, FMError>
fn from_generated_content(content: &GeneratedContent) -> Result<Self, FMError>
Source§impl Generable for GeneratedContent
impl Generable for GeneratedContent
Source§fn generation_schema() -> Result<GenerationSchema, FMError>
fn generation_schema() -> Result<GenerationSchema, FMError>
Self.Source§impl PartialEq for GeneratedContent
impl PartialEq for GeneratedContent
Source§fn eq(&self, other: &GeneratedContent) -> bool
fn eq(&self, other: &GeneratedContent) -> bool
self and other values to be equal, and is used by ==.