use super::graph::TranscriptHistoryState;
use super::validate::validate_transcript_history_state;
use crate::session::TranscriptEditError;
#[derive(Clone, Debug)]
pub struct ValidatedTranscriptHistory(std::sync::Arc<TranscriptHistoryState>);
impl ValidatedTranscriptHistory {
pub fn seal(
state: std::sync::Arc<TranscriptHistoryState>,
) -> Result<Self, TranscriptEditError> {
validate_transcript_history_state(&state)?;
Ok(Self(state))
}
pub fn seal_owned(state: TranscriptHistoryState) -> Result<Self, TranscriptEditError> {
Self::seal(std::sync::Arc::new(state))
}
pub(in crate::session) fn adopt_session_validated(
state: std::sync::Arc<TranscriptHistoryState>,
) -> Self {
Self(state)
}
pub(in crate::session) fn adopt_compacted_snapshot(
state: std::sync::Arc<TranscriptHistoryState>,
) -> Self {
Self(state)
}
#[must_use]
pub fn state(&self) -> &TranscriptHistoryState {
&self.0
}
#[must_use]
pub fn shared(&self) -> std::sync::Arc<TranscriptHistoryState> {
std::sync::Arc::clone(&self.0)
}
}
impl std::ops::Deref for ValidatedTranscriptHistory {
type Target = TranscriptHistoryState;
fn deref(&self) -> &Self::Target {
&self.0
}
}