Skip to main content

GeneratedContent

Struct GeneratedContent 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn from_elements<T>( elements: impl IntoIterator<Item = T>, ) -> Result<Self, FMError>

Build generated content from a sequence of values.

§Errors

Returns FMError if any element cannot be converted.

Source

pub fn from_elements_with_id<T>( elements: impl IntoIterator<Item = T>, generation_id: impl Into<Option<GenerationId>>, ) -> Result<Self, FMError>

Build generated content from a sequence of values with an ID.

§Errors

Returns FMError if any element cannot be converted.

Source

pub fn from_properties<K, V>( properties: impl IntoIterator<Item = (K, V)>, ) -> Result<Self, FMError>

Build generated content from key/value properties.

Later duplicates overwrite earlier ones.

§Errors

Returns FMError if any value cannot be converted.

Source

pub fn from_properties_with_id<K, V>( properties: impl IntoIterator<Item = (K, V)>, generation_id: impl Into<Option<GenerationId>>, ) -> Result<Self, FMError>

Build generated content from key/value properties with an ID.

Later duplicates overwrite earlier ones.

§Errors

Returns FMError if any value cannot be converted.

Source

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>

Build generated content from key/value properties, combining duplicates.

§Errors

Returns FMError if any value cannot be converted or combine fails.

Source

pub const fn raw_value(&self) -> &Value

Return the underlying JSON value.

Source

pub fn into_raw_value(self) -> Value

Consume the content and return the underlying JSON value.

Source

pub fn kind(&self) -> GeneratedContentKind

Return the typed content kind.

Source

pub fn json_string(&self) -> Result<String, FMError>

Serialize the content back to a compact JSON string.

§Errors

Returns FMError::Unknown if serialization fails.

Source

pub fn json_string_pretty(&self) -> Result<String, FMError>

Serialize the content as pretty JSON.

§Errors

Returns FMError::Unknown if serialization fails.

Source

pub fn value<T>(&self) -> Result<T, FMError>

Decode the content into a Rust value.

§Errors

Returns FMError::DecodingFailure if the JSON value does not match T.

Source

pub fn value_for_property<T>(&self, property: &str) -> Result<T, FMError>

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.

Source

pub const fn is_complete(&self) -> bool

Whether Apple’s structured stream reported this content as complete.

Source

pub fn generation_id(&self) -> Option<&str>

Apple’s opaque generation identifier, if one was attached.

Source

pub fn generation_id_handle(&self) -> Option<&GenerationId>

Borrow the typed generation identifier handle, if one was attached.

Source

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

Source§

fn clone(&self) -> GeneratedContent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GeneratedContent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for GeneratedContent

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<GeneratedContent> for Instructions

Source§

fn from(content: GeneratedContent) -> Self

Converts to this type from the input type.
Source§

impl From<GeneratedContent> for Prompt

Source§

fn from(content: GeneratedContent) -> Self

Converts to this type from the input type.
Source§

impl From<GeneratedContent> for ToolOutput

Source§

fn from(value: GeneratedContent) -> Self

Converts to this type from the input type.
Source§

impl From<GeneratedContent> for Value

Source§

fn from(value: GeneratedContent) -> Self

Converts to this type from the input type.
Source§

impl From<String> for GeneratedContent

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for GeneratedContent

Source§

fn from(values: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for GeneratedContent

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for GeneratedContent

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for GeneratedContent

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for GeneratedContent

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for GeneratedContent

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for GeneratedContent

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for GeneratedContent

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for GeneratedContent

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for GeneratedContent

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for GeneratedContent

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for GeneratedContent

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl FromGeneratedContent for GeneratedContent

Source§

fn from_generated_content(content: &GeneratedContent) -> Result<Self, FMError>

Decode a Rust value from generated content.
Source§

impl Generable for GeneratedContent

Source§

fn generation_schema() -> Result<GenerationSchema, FMError>

Return the generation schema that describes Self.
Source§

impl PartialEq for GeneratedContent

Source§

fn eq(&self, other: &GeneratedContent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToGeneratedContent for GeneratedContent

Source§

fn to_generated_content(&self) -> Result<GeneratedContent, FMError>

Convert a Rust value into generated content.
Source§

impl ToInstructions for &GeneratedContent

Source§

fn to_instructions(self) -> Result<Instructions, FMError>

Convert the value into instructions.
Source§

impl ToInstructions for GeneratedContent

Source§

fn to_instructions(self) -> Result<Instructions, FMError>

Convert the value into instructions.
Source§

impl ToPrompt for &GeneratedContent

Source§

fn to_prompt(self) -> Result<Prompt, FMError>

Convert the value into a prompt.
Source§

impl ToPrompt for GeneratedContent

Source§

fn to_prompt(self) -> Result<Prompt, FMError>

Convert the value into a prompt.
Source§

impl TryFrom<Value> for GeneratedContent

Source§

type Error = FMError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for GeneratedContent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.