31 lines
689 B
Rust
31 lines
689 B
Rust
use std::fmt;
|
|
|
|
/// API key wrapper that avoids exposing raw credentials in formatted output.
|
|
#[derive(Clone, Eq, PartialEq)]
|
|
pub struct ApiKey(String);
|
|
|
|
impl ApiKey {
|
|
pub fn new(value: impl Into<String>) -> Self {
|
|
Self(value.into())
|
|
}
|
|
|
|
pub fn expose_secret(&self) -> &str {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl fmt::Debug for ApiKey {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
formatter
|
|
.debug_tuple("ApiKey")
|
|
.field(&"<redacted>")
|
|
.finish()
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for ApiKey {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
formatter.write_str("<redacted>")
|
|
}
|
|
}
|