Struct async_nats::header::HeaderMap
source · pub struct HeaderMap { /* private fields */ }
Expand description
A struct for handling NATS headers. Has a similar API to http::header, but properly serializes and desiaralizes according to NATS requirements.
Examples
let client = async_nats::connect("demo.nats.io").await?;
let mut headers = async_nats::HeaderMap::new();
headers.insert("Key", "Value");
client.publish_with_headers("subject".to_string(), headers, "payload".into()).await?;
Implementations
sourceimpl HeaderMap
impl HeaderMap
pub fn iter(&self) -> Iter<'_, HeaderName, HeaderValue>
sourceimpl HeaderMap
impl HeaderMap
sourcepub fn insert<K: IntoHeaderName, V: IntoHeaderValue>(&mut self, name: K, value: V)
pub fn insert<K: IntoHeaderName, V: IntoHeaderValue>(&mut self, name: K, value: V)
sourcepub fn append<K: IntoHeaderName, V: ToString>(&mut self, name: K, value: V)
pub fn append<K: IntoHeaderName, V: ToString>(&mut self, name: K, value: V)
Appends a new value to the list of values to a given key. If the key did not exist, it will be inserted with provided value.
Examples
let mut headers = async_nats::HeaderMap::new();
headers.append("Key", "Value");
headers.append("Key", "Another");
sourcepub fn get<T: IntoHeaderName>(&self, name: T) -> Option<&HeaderValue>
pub fn get<T: IntoHeaderName>(&self, name: T) -> Option<&HeaderValue>
Gets a value for a given key. If key is not found, Option::None is returned.
Examples
let mut headers = async_nats::HeaderMap::new();
headers.append("Key", "Value");
let key = headers.get("Key").unwrap();
Trait Implementations
sourceimpl FromIterator<(HeaderName, HeaderValue)> for HeaderMap
impl FromIterator<(HeaderName, HeaderValue)> for HeaderMap
sourcefn from_iter<T: IntoIterator<Item = (HeaderName, HeaderValue)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (HeaderName, HeaderValue)>>(iter: T) -> Self
Creates a value from an iterator. Read more
impl Eq for HeaderMap
impl StructuralEq for HeaderMap
impl StructuralPartialEq for HeaderMap
Auto Trait Implementations
impl RefUnwindSafe for HeaderMap
impl Send for HeaderMap
impl Sync for HeaderMap
impl Unpin for HeaderMap
impl UnwindSafe for HeaderMap
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more