azure_storage_queue 0.5.0

Microsoft Azure Queue client library for Rust
Documentation
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT.

use super::QueueClientGetPropertiesResult;
use azure_core::{
    http::{
        headers::{HeaderName, Headers},
        NoFormat, Response,
    },
    Result,
};
use std::collections::HashMap;

const APPROXIMATE_MESSAGES_COUNT: HeaderName =
    HeaderName::from_static("x-ms-approximate-messages-count");
const META: &str = "x-ms-meta-";

/// Provides access to typed response headers for `QueueClient::get_properties()`
///
/// # Examples
///
/// ```no_run
/// use azure_core::{Result, http::{Response, NoFormat}};
/// use azure_storage_queue::models::{QueueClientGetPropertiesResult, QueueClientGetPropertiesResultHeaders};
/// async fn example() -> Result<()> {
///     let response: Response<QueueClientGetPropertiesResult, NoFormat> = unimplemented!();
///     // Access response headers
///     if let Some(approximate_messages_count) = response.approximate_messages_count()? {
///         println!("x-ms-approximate-messages-count: {:?}", approximate_messages_count);
///     }
///     println!("x-ms-meta: {:?}", response.metadata()?);
///     Ok(())
/// }
/// ```
pub trait QueueClientGetPropertiesResultHeaders: private::Sealed {
    fn approximate_messages_count(&self) -> Result<Option<i64>>;
    fn metadata(&self) -> Result<HashMap<String, String>>;
}

impl QueueClientGetPropertiesResultHeaders for Response<QueueClientGetPropertiesResult, NoFormat> {
    /// The approximate number of messages in the queue. This number is not lower than the actual number of
    /// messages in the queue, but could be higher.
    fn approximate_messages_count(&self) -> Result<Option<i64>> {
        Headers::get_optional_as(self.headers(), &APPROXIMATE_MESSAGES_COUNT)
    }

    /// The metadata headers.
    fn metadata(&self) -> Result<HashMap<String, String>> {
        let mut values = HashMap::new();
        for h in self.headers().iter() {
            let name = h.0.as_str();
            if name.len() > META.len() && name.starts_with(META) {
                values.insert(name[META.len()..].to_owned(), h.1.as_str().to_owned());
            }
        }
        Ok(values)
    }
}

mod private {
    use super::QueueClientGetPropertiesResult;
    use azure_core::http::{NoFormat, Response};

    pub trait Sealed {}

    impl Sealed for Response<QueueClientGetPropertiesResult, NoFormat> {}
}