Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica
Skip to main content

eidetica/account/
root.rs

1//! The typed Account handle exposed by an [`AccountSession`](super::AccountSession).
2
3use crate::{Database, entry::ID};
4
5/// An Account: the private root database of a person, group or application.
6///
7/// Its stable identity is the root ID returned by [`Account::id`], not a
8/// display name or the instance-local login ID. The backing [`Database`] is
9/// encapsulated: applications reach their stored references and the databases
10/// they name through [`AccountSession`](super::AccountSession) operations,
11/// which keep the Account's internal key and tracking stores out of reach.
12///
13/// Obtain it with [`AccountSession::account`](super::AccountSession::account).
14#[derive(Debug)]
15pub struct Account {
16    database: Database,
17}
18
19impl Account {
20    pub(crate) fn new(database: Database) -> Self {
21        Self { database }
22    }
23
24    /// Stable Account identity: the root ID of the Account database.
25    pub fn id(&self) -> &ID {
26        self.database.root_id()
27    }
28
29    /// The backing Account database, bound to the session's key.
30    ///
31    /// Test-only access for inspecting Account history; applications use the
32    /// session's reference operations instead.
33    #[cfg(any(test, feature = "testing"))]
34    pub fn database(&self) -> &Database {
35        &self.database
36    }
37
38    /// The backing Account database, bound to the session's key.
39    #[cfg(not(any(test, feature = "testing")))]
40    pub(crate) fn database(&self) -> &Database {
41        &self.database
42    }
43}