WriteReceipt

Struct WriteReceipt 

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

Write receipt

写入凭据

A receipt proving that a range has been successfully written.

This receipt can only be obtained after successfully writing through MmapFile::write_range, and can only be used to flush the corresponding range. This provides compile-time safety guarantees:

  • Can only flush ranges that have been written
  • Cannot flush ranges that have not been written

证明某个范围已被成功写入的凭据。

只有通过 MmapFile::write_range 成功写入后才能获得此凭据, 并且只能用于刷新对应的范围。这提供了编译期的安全保证:

  • 只能刷新已写入的范围
  • 不能刷新未写入的范围

§Examples

let (file, mut allocator) = MmapFile::create_default(&path, NonZeroU64::new(ALIGNMENT).unwrap())?;
let range = allocator.allocate(NonZeroU64::new(ALIGNMENT).unwrap()).unwrap();

// Write and get receipt
// 写入并获得凭据
let receipt = file.write_range(range, &vec![42u8; ALIGNMENT as usize]);

// Use receipt to flush the range
// 使用凭据刷新该范围
file.flush_range(receipt)?;

Implementations§

Source§

impl WriteReceipt

Source

pub fn range(&self) -> AllocatedRange

Get the range corresponding to this receipt

获取凭据对应的范围

Source

pub fn start(&self) -> u64

Get the start position of the range

获取范围的起始位置

Source

pub fn end(&self) -> u64

Get the end position of the range

获取范围的结束位置

Source

pub fn len(&self) -> u64

Get the length of the range

获取范围的长度

Source

pub fn is_empty(&self) -> bool

Check if the range is empty

检查范围是否为空

Trait Implementations§

Source§

impl Clone for WriteReceipt

Source§

fn clone(&self) -> WriteReceipt

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for WriteReceipt

Source§

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

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

impl PartialEq for WriteReceipt

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for WriteReceipt

Source§

impl Eq for WriteReceipt

Source§

impl StructuralPartialEq for WriteReceipt

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