pub struct GenState {
pub func: FunctionData,
pub args: Vec<Value>,
pub this: Value,
pub sent: Vec<GenCompletion>,
pub started: bool,
pub done: bool,
pub returned: Value,
}Expand description
Generator の状態(遅延評価 / replay 方式)。
真のコルーチン(スタック退避)は no_std ツリーウォーク実装では困難なため、
resume のたびに関数本体を先頭から再実行(replay)し、N 番目の yield で中断する。
既に通過した yield には sent(.next(v) で渡された値)を返すことで
双方向の値受け渡しと無限ジェネレータを実現する。
限界: replay のため本体の副作用(console.log 等)は resume ごとに再実行される。
Fields§
§func: FunctionDatagenerator 関数本体(params/body/closure を保持)。
args: Vec<Value>呼び出し時の実引数。
this: Value呼び出し時の this。
sent: Vec<GenCompletion>既に通過した各 yield に .next(v)/.throw(e)/.return(v) で渡された結果。
started: bool最初の .next() を消費済みか(最初の next の引数は捨てられる)。
done: bool完了済みか(以降の next は常に done:true)。
returned: Value完了時の return 値(done:true の value)。
Auto Trait Implementations§
impl !RefUnwindSafe for GenState
impl !Send for GenState
impl !Sync for GenState
impl !UnwindSafe for GenState
impl Freeze for GenState
impl Unpin for GenState
impl UnsafeUnpin for GenState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more