Skip to content

Commit 47c8daf

Browse files
Merge pull request #198 from brotskydotcom/issue-197
Make the default module alias public.
2 parents 3bbe2da + 676d4d9 commit 47c8daf

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords = ["password", "credential", "keychain", "keyring", "cross-platform"]
66
license = "MIT OR Apache-2.0"
77
name = "keyring"
88
repository = "https://github.com/hwchen/keyring-rs.git"
9-
version = "3.0.3"
9+
version = "3.0.4"
1010
rust-version = "1.75"
1111
edition = "2021"
1212
exclude = [".github/"]

src/credential.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,26 @@ This module defines a plug and play model for platform-specific credential store
66
The model comprises two traits: [CredentialBuilderApi] for the underlying store
77
and [CredentialApi] for the entries in the store. These traits must be implemented
88
in a thread-safe way, a requirement captured in the [CredentialBuilder] and
9-
[CredentialApi] types that wrap them.
9+
[Credential] types that wrap them.
10+
11+
Note that you must have an instance of a credential builder in
12+
your hands in order to call the [CredentialBuilder] API. Because each credential
13+
builder implementation lives in a platform-specific module, the cross-platform way to
14+
get your hands on the one currently being used to create entries is to ask
15+
for the builder from the `default` module alias. For example, to
16+
determine whether the credential builder currently being used
17+
persists its credentials across machine reboots, you might use a snippet like this:
18+
19+
```rust
20+
use keyring::{default, credential};
21+
22+
let persistence = default::default_credential_builder().persistence();
23+
if matches!(persistence, credential::CredentialPersistence::UntilDelete) {
24+
println!("The default credential builder persists credentials on disk!")
25+
} else {
26+
println!("The default credential builder doesn't persist credentials on disk!")
27+
}
28+
```
1029
*/
1130
use super::Result;
1231
use std::any::Any;

src/lib.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ then retrieving that as a password will return a
148148
[BadEncoding](Error::BadEncoding) error.
149149
The returned error will have the raw bytes attached,
150150
so you can access them, but you can also just fetch
151-
them directly using [Entry::get_secret] rather than
152-
[Entry:get_password].
151+
them directly using [get_secret](Entry::get_password) rather than
152+
[get_password](Entry::get_secret).
153153
154154
While this crate's code is thread-safe, the underlying credential
155155
stores may not handle access from different threads reliably.
@@ -182,7 +182,7 @@ compile_error!("You can enable at most one keystore per target architecture");
182182
#[cfg(all(target_os = "linux", feature = "linux-native"))]
183183
pub mod keyutils;
184184
#[cfg(all(target_os = "linux", feature = "linux-native"))]
185-
use keyutils as default;
185+
pub use keyutils as default;
186186

187187
#[cfg(all(
188188
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
@@ -193,7 +193,7 @@ pub mod secret_service;
193193
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
194194
any(feature = "sync-secret-service", feature = "async-secret-service")
195195
))]
196-
use secret_service as default;
196+
pub use secret_service as default;
197197

198198
#[cfg(all(
199199
target_os = "linux",
@@ -203,29 +203,29 @@ use secret_service as default;
203203
feature = "async-secret-service"
204204
))
205205
))]
206-
use mock as default;
206+
pub use mock as default;
207207
#[cfg(all(
208208
any(target_os = "freebsd", target_os = "openbsd"),
209209
not(any(feature = "sync-secret-service", feature = "async-secret-service"))
210210
))]
211-
use mock as default;
211+
pub use mock as default;
212212

213213
//
214214
// pick the Apple keystore
215215
//
216216
#[cfg(all(target_os = "macos", feature = "apple-native"))]
217217
pub mod macos;
218218
#[cfg(all(target_os = "macos", feature = "apple-native"))]
219-
use macos as default;
219+
pub use macos as default;
220220
#[cfg(all(target_os = "macos", not(feature = "apple-native")))]
221-
use mock as default;
221+
pub use mock as default;
222222

223223
#[cfg(all(target_os = "ios", feature = "apple-native"))]
224224
pub mod ios;
225225
#[cfg(all(target_os = "ios", feature = "apple-native"))]
226-
use ios as default;
226+
pub use ios as default;
227227
#[cfg(all(target_os = "ios", not(feature = "apple-native")))]
228-
use mock as default;
228+
pub use mock as default;
229229

230230
//
231231
// pick the Windows keystore
@@ -234,9 +234,9 @@ use mock as default;
234234
#[cfg(all(target_os = "windows", feature = "windows-native"))]
235235
pub mod windows;
236236
#[cfg(all(target_os = "windows", not(feature = "windows-native")))]
237-
use mock as default;
237+
pub use mock as default;
238238
#[cfg(all(target_os = "windows", feature = "windows-native"))]
239-
use windows as default;
239+
pub use windows as default;
240240

241241
#[cfg(not(any(
242242
target_os = "linux",
@@ -246,7 +246,7 @@ use windows as default;
246246
target_os = "ios",
247247
target_os = "windows",
248248
)))]
249-
use mock as default;
249+
pub use mock as default;
250250

251251
pub mod credential;
252252
pub mod error;

0 commit comments

Comments
 (0)