Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx<'a, P: Package> { /* private fields */ }
Expand description

The entry to state that command functions receive.

Effect commands get &mut Ctx<P>, query commands get &Ctx<P>. They can read and write only the state slice and persistent slice of their own package P, and can read the state of other packages only for those declared in P::DEPENDS (Ctx::dep). There is no time and no files.

Implementations§

Source§

impl<'a, P: Package> Ctx<'a, P>

Source

pub fn interrupted(&self) -> bool

Whether an interrupt is requested for the running VM (spec/host/01-execution.md, 1.9a). A long command checks this now and then, and returns CommandError::interrupted if it is true.

Source

pub fn state(&self) -> &P::State

The state slice of its own package (read).

Source

pub fn state_mut(&mut self) -> &mut P::State

The state slice of its own package (write). Only effect commands receive &mut Ctx.

Source

pub fn persistent(&self) -> &P::Persistent

The persistent slice of its own package (read).

Source

pub fn persistent_mut(&mut self) -> &mut P::Persistent

The persistent slice of its own package (write). Not undone by rollback.

Source

pub fn rng(&mut self) -> &mut Rng

The core’s random generator (the same sequence as random in scripts). Needs &mut, so only effect commands can use it.

Source

pub fn dep<Q: Package>(&self) -> Result<&Q::State, CommandError>

The state slice of dependency package Q (read only).

Err if Q is not in P::DEPENDS or is not registered (becomes a runtime error).

Auto Trait Implementations§

§

impl<'a, P> !RefUnwindSafe for Ctx<'a, P>

§

impl<'a, P> !UnwindSafe for Ctx<'a, P>

§

impl<'a, P> Forget for Ctx<'a, P>

§

impl<'a, P> Freeze for Ctx<'a, P>
where &'a mut <P as Package>::State: Freeze, &'a mut <P as Package>::Persistent: Freeze,

§

impl<'a, P> Move for Ctx<'a, P>

§

impl<'a, P> Send for Ctx<'a, P>
where &'a mut <P as Package>::State: Send, &'a mut <P as Package>::Persistent: Send,

§

impl<'a, P> Sync for Ctx<'a, P>
where &'a mut <P as Package>::State: Sync, &'a mut <P as Package>::Persistent: Sync,

§

impl<'a, P> Unpin for Ctx<'a, P>
where &'a mut <P as Package>::State: Unpin, &'a mut <P as Package>::Persistent: Unpin,

§

impl<'a, P> UnsafeUnpin for Ctx<'a, P>
where &'a mut <P as Package>::State: UnsafeUnpin, &'a mut <P as Package>::Persistent: UnsafeUnpin,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.