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
impl Eq for HeaderMap
impl StructuralPartialEq for HeaderMap
Auto Trait Implementations§
impl Freeze for HeaderMap
impl RefUnwindSafe for HeaderMap
impl Send for HeaderMap
impl Sync for HeaderMap
impl Unpin for HeaderMap
impl UnwindSafe for HeaderMap
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