#[non_exhaustive]pub struct Part { /* private fields */ }Expand description
Ergonomic wrapper over proto Part.
Implementations§
Source§impl Part
impl Part
pub fn text(text: impl Into<String>) -> Self
pub fn url(url: impl Into<String>, media_type: impl Into<String>) -> Self
pub fn raw(data: Vec<u8>, media_type: impl Into<String>) -> Self
pub fn data(value: Value) -> Self
pub fn with_filename(self, filename: impl Into<String>) -> Self
pub fn with_media_type(self, media_type: impl Into<String>) -> Self
Sourcepub fn as_data(&self) -> Option<Value>
pub fn as_data(&self) -> Option<Value>
Raw JSON view of a Data part. No number normalization.
Returns None if this is not a Data part.
Sourcepub fn parse_data<T: DeserializeOwned>(&self) -> Option<Result<T, A2aTypeError>>
pub fn parse_data<T: DeserializeOwned>(&self) -> Option<Result<T, A2aTypeError>>
Deserialize a Data part into T, normalizing proto f64 integers first.
Protobuf Value uses f64 for all numbers, so 25544 becomes 25544.0.
This normalizes whole-number f64s back to integers before deserializing,
so u32/i32/u8 fields work correctly.
Returns None if not a Data part. Returns Err if deserialization fails.
pub fn as_proto(&self) -> &Part
pub fn into_proto(self) -> Part
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Part
impl<'de> Deserialize<'de> for Part
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<Part> for Part
Wrap a proto Part without validation (content may be None).
Use TryFrom when you need to validate content is present.
impl From<Part> for Part
Wrap a proto Part without validation (content may be None).
Use TryFrom when you need to validate content is present.
Auto Trait Implementations§
impl Freeze for Part
impl RefUnwindSafe for Part
impl Send for Part
impl Sync for Part
impl Unpin for Part
impl UnsafeUnpin for Part
impl UnwindSafe for Part
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