oxedyne/fe2o3/fe2o3_datime/src/core/interval.rs
1.2 KiB, 12 runs
created by r1870400018:6349, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! [Written with AI entirely](https://need2know.ai/entirely-ai/code)\ |
| 2 | //! Anthropic Claude |
| 3 | |
| 4 | use crate::core::{ |
| 5 | Duration, |
| 6 | Time, |
| 7 | }; |
| 8 | |
| 9 | use oxedyne_fe2o3_core::prelude::*; |
| 10 | |
| 11 | use std::{ |
| 12 | fmt::Debug, |
| 13 | vec::Vec, |
| 14 | }; |
| 15 | |
| 16 | pub trait Interval<D: Duration>: Debug + Clone { |
| 17 | fn get_duration(&self) -> Outcome<D>; |
| 18 | |
| 19 | fn contains<T: Time>(&self, time: &T) -> bool; |
| 20 | |
| 21 | fn overlaps(&self, other: &Self) -> bool; |
| 22 | } |
| 23 | |
| 24 | #[derive(Clone, Debug, PartialEq)] |
| 25 | pub struct AbstractInterval; |
| 26 | |
| 27 | impl AbstractInterval { |
| 28 | pub fn new() -> Self { |
| 29 | Self |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | #[derive(Clone, Debug)] |
| 34 | pub struct IntervalList<I> { |
| 35 | intervals: Vec<I>, |
| 36 | } |
| 37 | |
| 38 | impl<I> IntervalList<I> { |
| 39 | pub fn new() -> Self { |
| 40 | Self { |
| 41 | intervals: Vec::new(), |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | pub fn add(&mut self, interval: I) { |
| 46 | self.intervals.push(interval); |
| 47 | } |
| 48 | |
| 49 | pub fn len(&self) -> usize { |
| 50 | self.intervals.len() |
| 51 | } |
| 52 | |
| 53 | pub fn is_empty(&self) -> bool { |
| 54 | self.intervals.is_empty() |
| 55 | } |
| 56 | |
| 57 | pub fn get(&self, index: usize) -> Option<&I> { |
| 58 | self.intervals.get(index) |
| 59 | } |
| 60 | |
| 61 | pub fn iter(&self) -> std::slice::Iter<I> { |
| 62 | self.intervals.iter() |
| 63 | } |
| 64 | } |