1use keyring::{Entry, Error, Result};
4
5#[derive(Clone, Debug, Eq, PartialEq)]
10pub struct KeyringEntry {
11 pub name: String,
12 pub service: String,
13}
14
15impl KeyringEntry {
16 pub fn new(name: impl ToString) -> Self {
20 Self {
21 name: name.to_string(),
22 service: env!("CARGO_CRATE_NAME").to_string(),
23 }
24 }
25
26 pub fn with_service(mut self, service: impl ToString) -> Self {
28 self.service = service.to_string();
29 self
30 }
31}
32
33impl TryFrom<KeyringEntry> for Entry {
34 type Error = Error;
35
36 fn try_from(entry: KeyringEntry) -> Result<Self> {
37 Entry::new(&entry.service, &entry.name)
38 }
39}