pub struct Session { /* private fields */ }Expand description
Owned guard over one beekeeper session.
Sessions don’t own the underlying C++ state — they share it with the
parent BeekeeperApi (and with any wallet
handles), so multiple sessions can be alive at once. Dropping the guard
closes the session; there is no explicit close call.
Implementations§
Source§impl Session
impl Session
Sourcepub fn is_temporary(self, is_temporary: bool) -> Self
pub fn is_temporary(self, is_temporary: bool) -> Self
Builder-style override for the is_temporary flag applied by
create_wallet.
When never called, wallets default to temporary if and only if the
beekeeper was opened with
BeekeeperOptions::in_memory.
let session = bk.create_session().unwrap().is_temporary(true);
let created = session.create_wallet("scratch", "password").unwrap();Sourcepub fn get_info(&self) -> SessionInfo
pub fn get_info(&self) -> SessionInfo
Capture a SessionInfo snapshot.
Does not mutate the activity clock.
Sourcepub fn has_wallet(&self, name: &str) -> Result<bool, BeekeeperError>
pub fn has_wallet(&self, name: &str) -> Result<bool, BeekeeperError>
true when a wallet with the given name exists in the underlying
wallet manager.
The check is process-wide, not session-scoped: any wallet known to the wallet manager counts, whether or not this session opened it.
Sourcepub fn list_wallets(&self) -> Result<Vec<WalletInfo>, BeekeeperError>
pub fn list_wallets(&self) -> Result<Vec<WalletInfo>, BeekeeperError>
All wallets currently opened in this session (locked or unlocked),
enriched with their is_temporary flag.
Sourcepub fn list_created_wallets(&self) -> Vec<WalletInfo>
pub fn list_created_wallets(&self) -> Vec<WalletInfo>
All wallets present on disk, opened or not.
Each entry is reported as unlocked: false; the is_temporary flag
is filled in from this session’s metadata if the wallet was created
or opened through this session in the past, otherwise defaults to
false.
In in-memory mode this returns an empty vector.
Sourcepub fn create_wallet<'p>(
&self,
name: &str,
password: impl Into<Option<&'p str>>,
) -> Result<CreatedWallet, BeekeeperError>
pub fn create_wallet<'p>( &self, name: &str, password: impl Into<Option<&'p str>>, ) -> Result<CreatedWallet, BeekeeperError>
Create a brand-new wallet and return it as a CreatedWallet.
password accepts anything convertible into Option<&str> — pass a
&str directly, or None to have the C++ side generate a random
password, returned in the CreatedWallet::password field.
Whether the wallet is temporary is controlled by the
is_temporary builder; unset, it defaults to
the beekeeper-wide
BeekeeperOptions::in_memory
flag.
Sourcepub fn open_wallet(&self, name: &str) -> Result<LockedWallet, BeekeeperError>
pub fn open_wallet(&self, name: &str) -> Result<LockedWallet, BeekeeperError>
Open an existing wallet and return its LockedWallet handle.
The wallet is registered with is_temporary: false because
previously-persisted wallets are by definition non-temporary.
Opening an already-open wallet is a no-op.
Sourcepub fn close_wallet(&self, name: &str) -> Result<(), BeekeeperError>
pub fn close_wallet(&self, name: &str) -> Result<(), BeekeeperError>
Close name on the C++ side and drop its metadata entry.
This does not lock the wallet first — call
UnlockedWallet::lock yourself
if the wallet is unlocked. The higher-level LockedWallet::close
and UnlockedWallet::close
methods do the right thing automatically.
Sourcepub fn lock_all(&self) -> Result<Vec<WalletInfo>, BeekeeperError>
pub fn lock_all(&self) -> Result<Vec<WalletInfo>, BeekeeperError>
Lock every unlocked wallet in this session and return the resulting
(post-lock) wallet listing, with every unlocked field false.
Wallets opened via a different handle of the same session are also locked.
Trait Implementations§
Source§impl Drop for Session
Locks everything in the session, then closes the session itself.
impl Drop for Session
Locks everything in the session, then closes the session itself.
Errors are ignored: the session may already have been closed by
BeekeeperApi::delete, in which
case this is a no-op.