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", headers, "payload".into())
.await?;
Implementations§
source§impl HeaderMap
impl HeaderMap
pub fn iter(&self) -> Iter<'_, HeaderName, Vec<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: 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)