1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::{Future, Generator, Stream, Value, Vm, VmError};
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum Call {
Async,
Stream,
Generator,
Immediate,
}
impl Call {
#[inline]
pub(crate) fn call_with_vm(self, vm: Vm) -> Result<Value, VmError> {
Ok(match self {
Call::Stream => Value::from(Stream::new(vm)),
Call::Generator => Value::from(Generator::new(vm)),
Call::Immediate => vm.complete()?,
Call::Async => Value::from(Future::new(vm.async_complete())),
})
}
}
impl fmt::Display for Call {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Stream => {
write!(fmt, "stream")?;
}
Self::Generator => {
write!(fmt, "generator")?;
}
Self::Immediate => {
write!(fmt, "immediate")?;
}
Self::Async => {
write!(fmt, "async")?;
}
}
Ok(())
}
}