pub struct Metadata { /* private fields */ }Expand description
An ordered, multi-valued map of custom gRPC metadata. Keys may repeat;
insertion order is preserved through the round-trip to and from
trillium::Headers.
Implementations§
Source§impl Metadata
impl Metadata
Sourcepub fn insert_ascii(
&mut self,
key: &str,
value: impl Into<String>,
) -> Result<(), MetadataError>
pub fn insert_ascii( &mut self, key: &str, value: impl Into<String>, ) -> Result<(), MetadataError>
Insert an ASCII metadata entry. Key must be lowercase
[0-9a-z_\-.]+, must not be reserved, and must not end in -bin.
Value must be printable ASCII (0x20–0x7E).
Sourcepub fn insert_binary(
&mut self,
key: &str,
value: impl Into<Vec<u8>>,
) -> Result<(), MetadataError>
pub fn insert_binary( &mut self, key: &str, value: impl Into<Vec<u8>>, ) -> Result<(), MetadataError>
Insert a binary metadata entry. Key must end in -bin and otherwise
follow the same rules as ASCII keys. Value bytes are base64-encoded
at write time.
Sourcepub fn get_ascii(&self, key: &str) -> Option<&str>
pub fn get_ascii(&self, key: &str) -> Option<&str>
Return the first ASCII value for key, if any.
Sourcepub fn get_binary(&self, key: &str) -> Option<&[u8]>
pub fn get_binary(&self, key: &str) -> Option<&[u8]>
Return the first binary value for key, if any.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &MetadataValue)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &MetadataValue)>
Iterate over (key, value) pairs in insertion order.
Sourcepub fn from_headers(headers: &Headers) -> Self
pub fn from_headers(headers: &Headers) -> Self
Pluck non-reserved entries out of headers. Binary -bin entries
are base64-decoded; entries that fail to decode or whose ASCII values
are not valid UTF-8 are skipped silently (the spec is lenient here —
we’d rather drop unparseable user metadata than fail the whole RPC).
Header names are normalized to lowercase. trillium’s KnownHeaderName
table presents canonical-case names (Content-Type, Retry-After,
…) even though the HTTP/2 wire is lowercase-only, so we lowercase
before matching against the reserved set and storing.
Sourcepub fn write_into(&self, headers: &mut Headers)
pub fn write_into(&self, headers: &mut Headers)
Append every entry to headers. Binary values are base64-encoded.
Multiple values for the same key produce multiple appended entries,
preserving wire order.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnsafeUnpin for Metadata
impl UnwindSafe for Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Server for Twhere
T: 'static,
impl<T> Server for Twhere
T: 'static,
Source§async fn unary<Req, Resp>(
conn: Conn,
f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<Resp, Status>,
) -> Conn
async fn unary<Req, Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<Resp, Status>, ) -> Conn
server only.grpc-status trailers.Source§async fn client_streaming<Resp>(
conn: Conn,
f: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<Resp, Status>,
) -> Conn
async fn client_streaming<Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<Resp, Status>, ) -> Conn
server only.GrpcServerConn from which they read
the request stream (conn.requests::<Req>()); emit the single response
frame and grpc-status trailers.Source§async fn server_streaming<Req, Resp, S>(
conn: Conn,
f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<S, Status>,
) -> Conn
async fn server_streaming<Req, Resp, S>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<S, Status>, ) -> Conn
server only.Stream, then frame each item lazily into the response body
with grpc-status trailers derived from how the stream ended.Source§async fn bidi<Req, Resp, R>(
conn: Conn,
prologue: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<R, Status>,
) -> Connwhere
Self: Codec<Req> + Codec<Resp>,
Req: Send + 'static,
Resp: Send + 'static,
R: BidiResponder<Req, Resp>,
async fn bidi<Req, Resp, R>(
conn: Conn,
prologue: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<R, Status>,
) -> Connwhere
Self: Codec<Req> + Codec<Resp>,
Req: Send + 'static,
Resp: Send + 'static,
R: BidiResponder<Req, Resp>,
server only.GrpcServerConn from which they may read early request messages (to decide
response headers) and set initial metadata, then return a
BidiResponder that drives the read-while-write loop after the head is
flushed. Returning Err(Status) rejects before the flush (trailers-only,
no upgrade). See crate::server::bidi for the seam mechanics.