Skip to main content

ShardedAccess

Struct ShardedAccess 

Source
pub struct ShardedAccess<'a, const SHARDS: usize> { /* private fields */ }
Expand description

A sharded collection that distributes entries across multiple accounts.

Each shard is an account containing a FixedVec<T>. The shard index is determined by a key hash.

This enables collections that exceed single-account size limits.

Implementations§

Source§

impl<'a, const SHARDS: usize> ShardedAccess<'a, SHARDS>

Source

pub fn new( accounts: &'a [AccountView], shard_indices: &[u8], ) -> Result<Self, ProgramError>

Create a sharded access from account indices.

Source

pub fn shard_for_key(&self, key: &[u8]) -> usize

Determine which shard a key maps to (simple modular hashing).

Source

pub fn shard_account( &self, shard: usize, ) -> Result<&'a AccountView, ProgramError>

Get the account for a given shard index.

Source

pub fn data_for_key(&self, key: &[u8]) -> Result<Ref<'a, [u8]>, ProgramError>

Get the account data for the shard that owns a given key.

Source

pub fn shard_count(&self) -> usize

Number of shards.

Auto Trait Implementations§

§

impl<'a, const SHARDS: usize> Freeze for ShardedAccess<'a, SHARDS>

§

impl<'a, const SHARDS: usize> RefUnwindSafe for ShardedAccess<'a, SHARDS>

§

impl<'a, const SHARDS: usize> Send for ShardedAccess<'a, SHARDS>

§

impl<'a, const SHARDS: usize> Sync for ShardedAccess<'a, SHARDS>

§

impl<'a, const SHARDS: usize> Unpin for ShardedAccess<'a, SHARDS>

§

impl<'a, const SHARDS: usize> UnsafeUnpin for ShardedAccess<'a, SHARDS>

§

impl<'a, const SHARDS: usize> UnwindSafe for ShardedAccess<'a, SHARDS>

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