aws_smithy_runtime_api/client/
connector_metadata.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! New-type for a configurable app name.
7
8use std::borrow::Cow;
9use std::fmt;
10
11/// The name of the crate that provides the HTTP connectors and its version.
12///
13/// This should be set by the connector's runtime plugin. Note that this is for
14/// the **connector** returned by an HTTP client, not the HTTP client itself.
15#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct ConnectorMetadata {
17    name: Cow<'static, str>,
18    version: Option<Cow<'static, str>>,
19}
20
21impl ConnectorMetadata {
22    /// Create a new [`ConnectorMetadata`].
23    pub fn new(name: impl Into<Cow<'static, str>>, version: Option<Cow<'static, str>>) -> Self {
24        Self {
25            name: name.into(),
26            version,
27        }
28    }
29
30    /// Return the name of the crate backing a connector.
31    pub fn name(&self) -> Cow<'static, str> {
32        self.name.clone()
33    }
34
35    /// Return the version of the crate backing a connector.
36    pub fn version(&self) -> Option<Cow<'static, str>> {
37        self.version.clone()
38    }
39}
40
41impl fmt::Display for ConnectorMetadata {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        write!(f, "http#{}", self.name)?;
44        if let Some(version) = self.version.as_deref() {
45            write!(f, "-{}", version)?;
46        }
47
48        Ok(())
49    }
50}