use keyring::{Entry, Error, Result};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct KeyringEntry {
pub name: String,
pub service: String,
}
impl KeyringEntry {
pub fn new(name: impl ToString) -> Self {
Self {
name: name.to_string(),
service: env!("CARGO_CRATE_NAME").to_string(),
}
}
pub fn with_service(mut self, service: impl ToString) -> Self {
self.service = service.to_string();
self
}
}
impl TryFrom<KeyringEntry> for Entry {
type Error = Error;
fn try_from(entry: KeyringEntry) -> Result<Self> {
Entry::new(&entry.service, &entry.name)
}
}