pub struct Session {
pub agents: Vec<SavedAgent>,
pub saved: BTreeMap<String, Value>,
pub repairs: Vec<Repair>,
}Expand description
A session as its logs left it.
Fields§
§agents: Vec<SavedAgent>Its agents, in the order their logs were started.
saved: BTreeMap<String, Value>The session’s own saved values by key: the SESSION log’s.
repairs: Vec<Repair>What reading it repaired or worked around.
Implementations§
Source§impl Session
impl Session
Sourcepub fn value<T: DeserializeOwned>(&self, key: &str) -> Option<Result<T, Error>>
pub fn value<T: DeserializeOwned>(&self, key: &str) -> Option<Result<T, Error>>
The session’s own saved value under key (the SESSION
log’s), read as a T: None when it has none, an error when the
value is not a T.
Sourcepub fn main_agent(&self) -> Option<&SavedAgent>
pub fn main_agent(&self) -> Option<&SavedAgent>
The main agent: the first by main_order of the agents a restore
brings back (not retired, nor spawned by one retired).
Source§impl Session
impl Session
Sourcepub fn read(store: &dyn Store) -> Result<Self, SessionError>
pub fn read(store: &dyn Store) -> Result<Self, SessionError>
Reads the session kept in store, without writing to it: a torn
last line is reported and left. Retired agents are read too.
§Errors
When the store fails, or any log is in another format or holds a record that cannot be read or does not apply: the whole session is refused.
Sourcepub fn read_lenient(
store: &dyn Store,
) -> Result<(Self, Vec<Unreadable>), SessionError>
pub fn read_lenient( store: &dyn Store, ) -> Result<(Self, Vec<Unreadable>), SessionError>
Reads each log of the session kept in store that reads, as
Self::read does, and sets aside each that does not, with why:
for a reader that shows what it can, such as an export or a search.
A restore reads strictly, so it never goes on from part of a
session.
§Errors
When the store cannot list its logs.
Sourcepub fn agent(&self, id: &str) -> Option<&SavedAgent>
pub fn agent(&self, id: &str) -> Option<&SavedAgent>
The agent id.
Sourcepub fn agent_mut(&mut self, id: &str) -> Option<&mut SavedAgent>
pub fn agent_mut(&mut self, id: &str) -> Option<&mut SavedAgent>
The agent id, to change it.
Sourcepub fn save(&mut self, store: &dyn Store) -> Result<(), SessionError>
pub fn save(&mut self, store: &dyn Store) -> Result<(), SessionError>
Saves the session to store, the one it was read from (or an empty
one): appends each agent’s unsaved changes (an agent new to the
store gets a header), its changed and removed saved values, and its
retirement, and the session’s changed values. Each agent’s
conversation is left with nothing unsaved. A torn last line of a log
written to is first set aside, as Writer::open
does.
§Errors
SessionError::Changed when a log that holds changes moved on since
the agent’s conversation was read, or holds another conversation,
before anything is written; when the store fails, a log is in another
format, or a line has no stamp; or when a write fails. It reads the
stamps of the logs’ changes, not the changes, so a change that does
not apply is refused by Self::read, not here.