pub struct Bank<G>where
G: Group,{ /* private fields */ }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 !Sendfn assert_sync<T: Sync>() {}
assert_sync::<Bank<GroupZero>>(); // ERROR: Bank is !SyncImplementations§
Source§impl<G> Bank<G>where
G: Group,
impl<G> Bank<G>where
G: Group,
Sourcepub const unsafe fn assume() -> Bank<G>
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.