spatialrust_episode/
annotate.rs1use crate::{EpisodeError, EpisodeResult};
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7pub enum AnnotationKind {
8 Label(String),
10 Scalar(String),
12}
13
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
16pub struct AnnotationSpan {
17 pub start_ns: u64,
19 pub end_ns: u64,
21}
22
23impl AnnotationSpan {
24 pub fn try_new(start_ns: u64, end_ns: u64) -> EpisodeResult<Self> {
26 if end_ns < start_ns {
27 return Err(EpisodeError::InvalidConfiguration("annotation span end < start".into()));
28 }
29 Ok(Self { start_ns, end_ns })
30 }
31}
32
33#[derive(Clone, Debug, PartialEq)]
35pub struct AnnotationLayer {
36 pub name: String,
38 pub items: Vec<(AnnotationSpan, AnnotationKind)>,
40}
41
42impl AnnotationLayer {
43 #[must_use]
45 pub fn new(name: impl Into<String>) -> Self {
46 Self { name: name.into(), items: Vec::new() }
47 }
48
49 pub fn push(&mut self, span: AnnotationSpan, kind: AnnotationKind) {
51 self.items.push((span, kind));
52 }
53}