use crate::error::Error;
use rs_teststand::Engine;
use rs_teststand::sequence::{ConflictHandler, GetSeqFileOptions, SequenceFile};
#[derive(Debug)]
pub struct SequenceFileGuard<'a> {
engine: &'a Engine,
file: Option<SequenceFile>,
}
impl<'a> SequenceFileGuard<'a> {
pub fn load(
engine: &'a Engine,
path: &str,
options: GetSeqFileOptions,
handler: ConflictHandler,
) -> Result<Self, Error> {
let file = engine.get_sequence_file_ex(path, options, handler)?;
Ok(Self {
engine,
file: Some(file),
})
}
#[must_use]
pub const fn file(&self) -> Option<&SequenceFile> {
self.file.as_ref()
}
}
impl Drop for SequenceFileGuard<'_> {
fn drop(&mut self) {
if let Some(file) = self.file.take() {
let _ = self.engine.release_sequence_file_ex(file, 0);
}
}
}