pub struct KeyringClient<'a> { /* private fields */ }Expand description
This Keyring Client interacts with the OS specific keyring to store a secret.
§Keyring Backends:
- Windows - wincred
- Linux - Secret Service
- Mac - Security Framework
Implementations§
Source§impl<'a> KeyringClient<'a>
impl<'a> KeyringClient<'a>
Sourcepub fn new(
username: &'a str,
service: &'a str,
application: &'a str,
) -> Result<Self>
pub fn new( username: &'a str, service: &'a str, application: &'a str, ) -> Result<Self>
Returns a new keyring client
§Arguments
username- The username to store secrets underservice- A unique identifier within your applicationapplication- The name of your application
Examples found in repository?
examples/example.rs (line 9)
4fn main() -> Result<()> {
5 let username = "tmuntaner";
6 let service = "keyring-rs-example";
7 let application = "keyring-rs";
8
9 let keyring = KeyringClient::new(username, service, application)?;
10 let password = String::from("foobar");
11
12 println!("Setting password {}", password);
13 keyring.set_password(password.clone())?;
14
15 let result = keyring
16 .get_password()?
17 .ok_or_else(|| anyhow!("should have a password"))?;
18 println!("Returned password: {}", password);
19 assert_eq!(password, result);
20
21 Ok(())
22}Sourcepub fn set_password(&self, password: String) -> Result<()>
pub fn set_password(&self, password: String) -> Result<()>
Examples found in repository?
examples/example.rs (line 13)
4fn main() -> Result<()> {
5 let username = "tmuntaner";
6 let service = "keyring-rs-example";
7 let application = "keyring-rs";
8
9 let keyring = KeyringClient::new(username, service, application)?;
10 let password = String::from("foobar");
11
12 println!("Setting password {}", password);
13 keyring.set_password(password.clone())?;
14
15 let result = keyring
16 .get_password()?
17 .ok_or_else(|| anyhow!("should have a password"))?;
18 println!("Returned password: {}", password);
19 assert_eq!(password, result);
20
21 Ok(())
22}Sourcepub fn get_password(&self) -> Result<Option<String>>
pub fn get_password(&self) -> Result<Option<String>>
Examples found in repository?
examples/example.rs (line 16)
4fn main() -> Result<()> {
5 let username = "tmuntaner";
6 let service = "keyring-rs-example";
7 let application = "keyring-rs";
8
9 let keyring = KeyringClient::new(username, service, application)?;
10 let password = String::from("foobar");
11
12 println!("Setting password {}", password);
13 keyring.set_password(password.clone())?;
14
15 let result = keyring
16 .get_password()?
17 .ok_or_else(|| anyhow!("should have a password"))?;
18 println!("Returned password: {}", password);
19 assert_eq!(password, result);
20
21 Ok(())
22}Auto Trait Implementations§
impl<'a> Freeze for KeyringClient<'a>
impl<'a> !RefUnwindSafe for KeyringClient<'a>
impl<'a> Send for KeyringClient<'a>
impl<'a> Sync for KeyringClient<'a>
impl<'a> Unpin for KeyringClient<'a>
impl<'a> !UnwindSafe for KeyringClient<'a>
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