Skip to main content

Anchor

Struct Anchor 

Source
pub struct Anchor(/* private fields */);
Available on crate feature bank only.
Expand description

Proof that the holder runs in bank 0 (the always-mapped region), and so may run a closure across a bank switch via scope / there.

Those operations lend a closure across a switch; the closure’s code must stay mapped while it runs, which only holds for code in bank 0. An Anchor is that guarantee, as a zero-sized Copy capability. The #[bank::main] and #[bank::zero] macros mint one at the top of every body (their code is in bank 0); a #[bank] function gets none, so it cannot reach scope / there, which would otherwise run a banked closure the switch unmaps.

Being Copy, it threads into nested scopes without borrow friction.

Implementations§

Source§

impl Anchor

Source

pub const unsafe fn assume() -> Anchor

Assert that the calling code runs in bank 0.

§Safety

The caller must physically reside in bank 0 (the always-mapped region): a #[bank::main] / #[bank::zero] body, or a plain fn the linker keeps in bank 0. A #[bank] function is not in bank 0 and must never mint one.

An Anchor must also not be moved into #[bank] code: it witnesses that the current code is in bank 0, which carrying it into a banked function would falsify. (Safe code cannot do this: the macro-minted Anchor is hygienic and there is no other safe constructor.)

Trait Implementations§

Source§

impl !BankSafe for Anchor

Source§

impl Clone for Anchor

Source§

fn clone(&self) -> Anchor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Anchor

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.