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", headers, "payload".into())
.await?;
Implementations§
Source§impl HeaderMap
impl HeaderMap
pub fn iter(&self) -> Iter<'_, HeaderName, Vec<HeaderValue>>
Source§impl HeaderMap
impl HeaderMap
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: IntoHeaderValue>(
&mut self,
name: K,
value: V,
)
pub fn append<K: IntoHeaderName, V: IntoHeaderValue>( &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
use async_nats::HeaderMap;
let mut headers = HeaderMap::new();
headers.append("Key", "Value");
headers.append("Key", "Another");
Sourcepub fn get<K: IntoHeaderName>(&self, key: K) -> Option<&HeaderValue>
pub fn get<K: IntoHeaderName>(&self, key: K) -> Option<&HeaderValue>
Gets a value for a given key. If key is not found, Option::None is returned.
§Examples
let mut headers = HeaderMap::new();
headers.append("Key", "Value");
let values = headers.get("Key").unwrap();
Sourcepub fn get_last<K: IntoHeaderName>(&self, key: K) -> Option<&HeaderValue>
pub fn get_last<K: IntoHeaderName>(&self, key: K) -> Option<&HeaderValue>
Gets a last value for a given key. If key is not found, Option::None is returned.
§Examples
let mut headers = HeaderMap::new();
headers.append("Key", "Value");
let values = headers.get_last("Key").unwrap();
Sourcepub fn get_all<K: IntoHeaderName>(&self, key: K) -> GetAll<'_, HeaderValue> ⓘ
pub fn get_all<K: IntoHeaderName>(&self, key: K) -> GetAll<'_, HeaderValue> ⓘ
Gets an iterator to the values for a given key.
§Examples
let mut headers = HeaderMap::new();
headers.append("Key", "Value1");
headers.append("Key", "Value2");
let mut values = headers.get_all("Key");
let value1 = values.next();
let value2 = values.next();
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HeaderMap
impl<'de> Deserialize<'de> for HeaderMap
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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