gc_sequence/sequence.rs
1use alloc::boxed::Box;
2use gc_arena::{Collect, MutationContext};
3
4/// A trait that describes a sequence of actions to perform, in between which garbage collection may
5/// take place.
6///
7/// This trait is similar to the `Future` trait in that it is not designed to be used directly, but
8/// rather chained together using combinators and run to completion with a sequencer.
9pub trait Sequence<'gc>: Collect {
10 type Output;
11
12 fn step(&mut self, mc: MutationContext<'gc, '_>) -> Option<Self::Output>;
13}
14
15impl<'gc, T: ?Sized + Sequence<'gc>> Sequence<'gc> for Box<T> {
16 type Output = T::Output;
17
18 fn step(&mut self, mc: MutationContext<'gc, '_>) -> Option<Self::Output> {
19 T::step(&mut (*self), mc)
20 }
21}