TryIntoContent

Trait TryIntoContent 

Source
pub trait TryIntoContent {
    // Required method
    fn try_into_content(self) -> Result<Content, Error>;
}
Expand description

Fallible conversion to a single Content item

See TryIntoContents for usage patterns. Prefer IntoContent for infallible conversions.

§Example

use google_ai_rs::{TryIntoContent, Content, Part, Error};

struct ValidatedInput(String);

impl TryIntoContent for ValidatedInput {
    fn try_into_content(self) -> Result<Content, Error> {
        if self.0.is_empty() {
            Err(Error::InvalidContent("Input cannot be empty".into()))
        } else {
            Ok(Content::new(self.0))
        }
    }
}

Required Methods§

Source

fn try_into_content(self) -> Result<Content, Error>

Convert to a content item with validation

Implementors§