Skip to main content

GenState

Struct GenState 

Source
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: FunctionData

generator 関数本体(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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.