Skip to main content

SlotDirectory

Struct SlotDirectory 

Source
pub struct SlotDirectory { /* private fields */ }
Expand description

8 个槽位的目录。

Implementations§

Source§

impl SlotDirectory

Source

pub const fn new() -> Self

全空的目录。

Source

pub const fn entries(&self) -> &[SlotEntry; 8]

借出全部条目。

Source

pub fn get(&self, i: usize) -> Option<SlotEntry>

取第 i 个槽位。越界返回 None。

Source

pub fn set(&mut self, i: usize, e: SlotEntry) -> Result<()>

设置第 i 个槽位。

§Errors

下标越界时返回 Error::TooManySlots。

Source

pub fn first_free(&self) -> Option<usize>

找一个真正空闲的槽位。

这正是可管理模式的核心价值:可否认模式下没有这种操作可用,add 只能把新密码写在 keep.len() 那个下标上,赌它原来是空的。

Source

pub fn used(&self) -> usize

占用了几个槽位。

Source

pub fn indices_of(&self, kind: SlotKind) -> Vec<usize>

列出某个类型占用的全部下标。

Source

pub fn encode(&self) -> Vec<u8> ⓘ

编码成固定 24 字节。

Source

pub fn decode(raw: &[u8]) -> Result<Self>

从 24 字节解码。

§Errors

长度不是 DIRECTORY_LEN 时返回 Error::MalformedTlv。长度不对 就拒绝而不是尽力解析:目录与 slot 区必须严格对应,一个解析出 5 项 的「目录」比没有目录更危险——用户会拿它去删协作者。

Trait Implementations§

Source§

impl Clone for SlotDirectory

Source§

fn clone(&self) -> Self

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 SlotDirectory

Source§

impl Debug for SlotDirectory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SlotDirectory

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for SlotDirectory

Source§

impl PartialEq for SlotDirectory

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SlotDirectory

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.