pub struct ApiKey { /* private fields */ }Expand description
Validated API key used by provider configuration.
The key is a nonempty, syntax-valid secret; construction neither authenticates it nor proves provider permissions. Empty values, whitespace-only values, and values with leading or trailing whitespace are rejected at construction. Values must also be valid HTTP header values; embedded control characters such as newlines are rejected.
§Examples
let key = providers_kit::config::ApiKey::new("sk-test")?;
assert!(!format!("{key:?}").contains("sk-test"));
Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn new(secret: impl Into<String>) -> Result<Self, KitError>
pub fn new(secret: impl Into<String>) -> Result<Self, KitError>
Validates and stores an API key.
§Errors
Returns a configuration error when the secret is empty, whitespace-only, contains leading or trailing whitespace, or is not a valid HTTP header value.
§Examples
let key = providers_kit::config::ApiKey::new("sk-test")?;
assert!(!format!("{key:?}").contains("sk-test"));
assert!(providers_kit::config::ApiKey::new(" padded ").is_err());
assert!(providers_kit::config::ApiKey::new("invalid\nheader").is_err());
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiKey
impl RefUnwindSafe for ApiKey
impl Send for ApiKey
impl Sync for ApiKey
impl Unpin for ApiKey
impl UnsafeUnpin for ApiKey
impl UnwindSafe for ApiKey
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