pub struct Map<T> { /* private fields */ }
Expand description
A wrapper type to represent maps in Google Schema-friendly format.
Google Schema doesn’t natively support maps, so this represents them as arrays
of key-value pairs using the Entry
struct. Provides schema generation through
AsSchema
and optional serde deserialization.
§Examples
Basic usage with HashMap:
use std::collections::HashMap;
use google_ai_rs::{Map, Schema, AsSchema};
type MyMap = Map<HashMap<String, i32>>;
let schema = Schema {
r#type: SchemaType::Array as i32,
items: Some(
Schema {
r#type: SchemaType::Object as i32,
properties: [
("key".to_string(), String::as_schema()),
("value".to_string(), i32::as_schema()),
]
.into(),
required: ["key".to_string(), "value".to_string()].into(),
..Default::default()
}
.into(),
),
nullable: true,
..Default::default()
};
assert_eq!(schema, MyMap::as_schema())
Custom field identifiers and description:
use google_ai_rs::{MapTrait, Map};
struct CustomMap;
impl MapTrait for CustomMap {
type Key = String;
type Value = i32;
const KEY_IDENT: &str = "id";
const VALUE_IDENT: &str = "count";
const DESCRIPTION: Option<&str> = Some("Custom mapped values");
}
type SpecialMap = Map<CustomMap>;
// Schema will have "id" and "count" fields with description
Deserialization Note:
Requires serde
feature. Works best when T
uses MapAccess::next_entry
variants.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Map<T>where
T: Freeze,
impl<T> RefUnwindSafe for Map<T>where
T: RefUnwindSafe,
impl<T> Send for Map<T>where
T: Send,
impl<T> Sync for Map<T>where
T: Sync,
impl<T> Unpin for Map<T>where
T: Unpin,
impl<T> UnwindSafe for Map<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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request