oxedyne/fe2o3/fe2o3_datime/src/core/list.rs
1.5 KiB, 7 runs
created by r1870400018:6353, 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::Time; |
| 5 | |
| 6 | use oxedyne_fe2o3_core::prelude::*; |
| 7 | |
| 8 | use std::{ |
| 9 | fmt::Debug, |
| 10 | vec::Vec, |
| 11 | }; |
| 12 | |
| 13 | #[derive(Clone, Debug)] |
| 14 | pub struct TimeList<T: Time> { |
| 15 | times: Vec<T>, |
| 16 | } |
| 17 | |
| 18 | impl<T: Time> TimeList<T> { |
| 19 | pub fn new() -> Self { |
| 20 | Self { |
| 21 | times: Vec::new(), |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | pub fn add(&mut self, time: T) { |
| 26 | self.times.push(time); |
| 27 | } |
| 28 | |
| 29 | pub fn len(&self) -> usize { |
| 30 | self.times.len() |
| 31 | } |
| 32 | |
| 33 | pub fn is_empty(&self) -> bool { |
| 34 | self.times.is_empty() |
| 35 | } |
| 36 | |
| 37 | pub fn get(&self, index: usize) -> Option<&T> { |
| 38 | self.times.get(index) |
| 39 | } |
| 40 | |
| 41 | pub fn first(&self) -> Option<&T> { |
| 42 | self.times.first() |
| 43 | } |
| 44 | |
| 45 | pub fn last(&self) -> Option<&T> { |
| 46 | self.times.last() |
| 47 | } |
| 48 | |
| 49 | pub fn iter(&self) -> std::slice::Iter<T> { |
| 50 | self.times.iter() |
| 51 | } |
| 52 | |
| 53 | pub fn remove(&mut self, start: usize, end: usize) -> Outcome<()> { |
| 54 | if end < start { |
| 55 | return Err(err!( |
| 56 | "Invalid range: end {} < start {}", |
| 57 | end, start; |
| 58 | Invalid, Input, Range)); |
| 59 | } |
| 60 | |
| 61 | if end >= self.times.len() { |
| 62 | return Err(err!( |
| 63 | "End index {} out of bounds (len: {})", |
| 64 | end, self.times.len(); |
| 65 | Invalid, Input, Range)); |
| 66 | } |
| 67 | |
| 68 | self.times.drain(start..=end); |
| 69 | Ok(()) |
| 70 | } |
| 71 | |
| 72 | pub fn size(&self) -> usize { |
| 73 | self.len() |
| 74 | } |
| 75 | } |