pub trait EpisodeDriver: Send + Sync {
// Required methods
fn open(&self, provider: &str, external_id: &str) -> String;
fn close(
&self,
provider: &str,
external_id: &str,
reason: CloseReason,
) -> String;
}Expand description
What opens and closes the repository’s own episode.
One trait with one real implementation, because the alternative was for this module to
learn how a session record is written — and a second writer of the record the provider
hooks already write is exactly the repeated semantic definition this repository refuses
(ADR 0004). ToolDriver runs majordomus capture session, the same command, with the
same payload shape, through the same adapter resolution.
A driver of one’s own is how a board is driven without a repository; what it returns is
what the episode’s repository field carries:
use majordomus_cli::episodes::{CloseReason, EpisodeBoard, EpisodeDriver};
use majordomus_cli::peers::{PeerBoard, Transport};
struct Echo;
impl EpisodeDriver for Echo {
fn open(&self, provider: &str, id: &str) -> String { format!("opened {provider} {id}") }
fn close(&self, _: &str, id: &str, reason: CloseReason) -> String {
format!("closed {id} ({})", reason.as_str())
}
}
let board = EpisodeBoard::with_driver(Box::new(Echo));
let peer = PeerBoard::new().attach(Transport::Stdio);
assert_eq!(board.attach(&peer, "t1", "generic").0.repository, "opened generic t1");
assert_eq!(board.close("t1", CloseReason::Shutdown).unwrap().repository, "closed t1 (shutdown)");Required Methods§
Sourcefn open(&self, provider: &str, external_id: &str) -> String
fn open(&self, provider: &str, external_id: &str) -> String
Open the episode for external_id under provider. Returns what to record in
ConnectionEpisode::repository — a description of what happened, successful or not.
It is called once per episode, on the first attach; a resume does not call it again.
use majordomus_cli::episodes::{EpisodeDriver, NullDriver};
let said = NullDriver.open("generic", "t1");
assert!(said.starts_with("no repository episode"), "a driver never answers blank");Sourcefn close(
&self,
provider: &str,
external_id: &str,
reason: CloseReason,
) -> String
fn close( &self, provider: &str, external_id: &str, reason: CloseReason, ) -> String
Close it, with the reason the record is to carry. Returns what the repository did,
which replaces the episode’s repository field on the way out.
use majordomus_cli::episodes::{CloseReason, EpisodeDriver, NullDriver};
let said = NullDriver.close("generic", "t1", CloseReason::Expired);
assert!(said.contains("without a driver"));Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".