Skip to main content

Bank

Struct Bank 

Source
pub struct Bank<G>
where G: Group,
{ /* private fields */ }
Available on crate feature bank only.
Expand description

A witness that group G’s bank is currently mapped.

This is the GhostCell-style permission token: a zero-sized value whose type G is the brand. Borrowing it shared (local) yields references into the bank; borrowing it &mut (a switch via scope) is what changes the mapping. Because you cannot do both at once, a reference obtained from local can never be live across a switch; the conflict is a borrow error.

The token is !Send and only mintable through assume (or, safely, the closure argument of scope).

§Examples

fn play(b: &mut Bank<Sound>) {
    let note = *b.local(&MELODY);   // `b` proves Sound is mapped
    // ...
}

The token is !Send and !Sync: a “this bank is mapped” proof cannot cross threads, nor be parked in a static and read back later.

fn assert_send<T: Send>() {}
assert_send::<Bank<GroupZero>>(); // ERROR: Bank is !Send
fn assert_sync<T: Sync>() {}
assert_sync::<Bank<GroupZero>>(); // ERROR: Bank is !Sync

Implementations§

Source§

impl<G> Bank<G>
where G: Group,

Source

pub const unsafe fn assume() -> Bank<G>

Mint a token, asserting that group G’s bank is already mapped.

This is the escape hatch for hand-rolled control: after a raw switch_bank or inline asm, call assume to re-enter the safe local / scope API.

§Safety

Group G’s bank must actually be mapped at the call site; otherwise every subsequent local/call through this token reads the wrong bank.

Trait Implementations§

Source§

impl<G> !Send for Bank<G>
where G: Group,

Source§

impl<G> !Sync for Bank<G>
where G: Group,

Auto Trait Implementations§

§

impl<G> BankSafe for Bank<G>
where G: BankSafe,

§

impl<G> Freeze for Bank<G>

§

impl<G> RefUnwindSafe for Bank<G>
where G: RefUnwindSafe,

§

impl<G> Unpin for Bank<G>
where G: Unpin,

§

impl<G> UnsafeUnpin for Bank<G>

§

impl<G> UnwindSafe for Bank<G>
where G: UnwindSafe,

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> 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.