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 deserializes 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§
source§impl HeaderMap
impl HeaderMap
pub fn iter(&self) -> Iter<'_, HeaderName, HeaderValue>
source§impl 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§
source§impl FromIterator<(HeaderName, HeaderValue)> for HeaderMap
impl FromIterator<(HeaderName, HeaderValue)> for HeaderMap
source§fn 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