1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
56//! New-type for a configurable app name.
78use std::borrow::Cow;
9use std::fmt;
1011/// 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}
2021impl ConnectorMetadata {
22/// Create a new [`ConnectorMetadata`].
23pub fn new(name: impl Into<Cow<'static, str>>, version: Option<Cow<'static, str>>) -> Self {
24Self {
25 name: name.into(),
26 version,
27 }
28 }
2930/// Return the name of the crate backing a connector.
31pub fn name(&self) -> Cow<'static, str> {
32self.name.clone()
33 }
3435/// Return the version of the crate backing a connector.
36pub fn version(&self) -> Option<Cow<'static, str>> {
37self.version.clone()
38 }
39}
4041impl fmt::Display for ConnectorMetadata {
42fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43write!(f, "http#{}", self.name)?;
44if let Some(version) = self.version.as_deref() {
45write!(f, "-{}", version)?;
46 }
4748Ok(())
49 }
50}