1use gc_arena::{Collect, MutationContext};
2
3use crate::Sequence;
4
5#[must_use = "sequences do nothing unless stepped"]
6#[derive(Debug, Collect)]
7#[collect(no_drop)]
8pub struct Done<O>(Option<O>);
9
10impl<'gc, O: Collect> Sequence<'gc> for Done<O> {
11 type Output = O;
12
13 fn step(&mut self, _: MutationContext<'gc, '_>) -> Option<O> {
14 Some(self.0.take().expect("cannot step a finished sequence"))
15 }
16}
17
18pub fn done<T>(t: T) -> Done<T> {
19 Done(Some(t))
20}
21
22pub fn ok<T, E>(t: T) -> Done<Result<T, E>> {
23 Done(Some(Ok(t)))
24}
25
26pub fn err<T, E>(e: E) -> Done<Result<T, E>> {
27 Done(Some(Err(e)))
28}