orx_iterable/obj_safe/sources/
once.rs1use crate::{
2 obj_safe::{CollectionMutObj, CollectionObj, IterableObj},
3 sources::{Once, OnceCol},
4};
5use std::boxed::Box;
6
7impl<T> IterableObj for Once<T>
8where
9 T: Clone,
10{
11 type Item = T;
12
13 fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
14 Box::new(core::iter::once(self.value.clone()))
15 }
16}
17
18impl<T> IterableObj for core::iter::Once<T>
19where
20 T: Clone,
21{
22 type Item = T;
23
24 fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
25 Box::new(self.clone())
26 }
27}
28
29impl<'a, T> IterableObj for &'a OnceCol<T> {
32 type Item = &'a T;
33
34 fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
35 Box::new(core::iter::once(&self.value))
36 }
37}
38
39impl<T> CollectionObj for OnceCol<T> {
40 type Item = T;
41
42 fn boxed_iter(&self) -> Box<dyn Iterator<Item = &Self::Item> + '_> {
43 Box::new(core::iter::once(&self.value))
44 }
45}
46
47impl<T> CollectionMutObj for OnceCol<T> {
48 fn boxed_iter_mut(&mut self) -> Box<dyn Iterator<Item = &mut Self::Item> + '_> {
49 Box::new(core::iter::once(&mut self.value))
50 }
51}