dfir_rs/scheduled/handoff/
mod.rs1pub mod handoff_list;
4mod tee;
5mod vector;
6
7use std::any::Any;
8use std::cell::{RefCell, RefMut};
9use std::rc::Rc;
10
11pub use tee::TeeingHandoff;
12pub use vector::VecHandoff;
13
14pub trait TryCanReceive<T> {
16 fn try_give(&self, item: T) -> Result<T, T>;
19}
20
21pub trait CanReceive<T> {
23 fn give(&self, item: T) -> T;
26}
27
28pub trait HandoffMeta: Any {
30 fn is_bottom(&self) -> bool;
33}
34
35impl<H> HandoffMeta for Rc<RefCell<H>>
36where
37 H: HandoffMeta,
38{
39 fn is_bottom(&self) -> bool {
40 self.borrow().is_bottom()
41 }
42}
43
44pub trait Handoff: Default + HandoffMeta {
46 type Inner;
48
49 fn take_inner(&self) -> Self::Inner;
51
52 fn borrow_mut_swap(&self) -> RefMut<'_, Self::Inner>;
56
57 fn give<T>(&self, item: T) -> T
59 where
60 Self: CanReceive<T>,
61 {
62 <Self as CanReceive<T>>::give(self, item)
63 }
64
65 fn try_give<T>(&self, item: T) -> Result<T, T>
67 where
68 Self: TryCanReceive<T>,
69 {
70 <Self as TryCanReceive<T>>::try_give(self, item)
71 }
72}
73
74#[repr(transparent)]
76#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
77pub struct Iter<I>(pub I)
78where
79 I: IntoIterator;
80impl<I> IntoIterator for Iter<I>
81where
82 I: IntoIterator,
83{
84 type Item = I::Item;
85 type IntoIter = I::IntoIter;
86
87 fn into_iter(self) -> Self::IntoIter {
88 self.0.into_iter()
89 }
90}