AllocatedRange

Struct AllocatedRange 

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

Allocated file range

已分配的文件范围

Represents a valid range [start, end) allocated through RangeAllocator. This type can only be created through the allocator, guaranteeing that all ranges are non-overlapping.

表示通过 RangeAllocator 分配的有效范围 [start, end)。 此类型只能通过分配器创建,保证所有范围不重叠。

§Range Format

Uses half-open interval [start, end):

  • start: Inclusive start position
  • end: Exclusive end position

For example: AllocatedRange { start: 0, end: 10 } represents bytes 0-9 (10 bytes total)

§范围格式

使用左闭右开区间 [start, end)

  • start: 包含的起始位置
  • end: 不包含的结束位置

例如:AllocatedRange { start: 0, end: 10 } 表示字节 0-9(共 10 字节)

§Safety Guarantees

  • start is always ≤ end
  • Can only be created through the allocator, preventing overlaps
  • Provides immutable access, preventing modification

§安全性保证

  • start 总是小于等于 end
  • 只能通过分配器创建,防止重叠
  • 提供不可变访问,防止修改

§Examples

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

// Get range information (4K aligned)
// 获取范围信息(4K对齐)
assert_eq!(range.start(), 0);
assert_eq!(range.end(), ALIGNMENT);
assert_eq!(range.len(), ALIGNMENT);

let (start, end) = range.as_range_tuple();
assert_eq!(start, 0);
assert_eq!(end, ALIGNMENT);

Implementations§

Source§

impl AllocatedRange

Source

pub fn start(&self) -> u64

Get the start position

获取起始位置

§Returns

The start position of the range (inclusive)

§返回值

返回范围的起始位置(包含)

Source

pub fn end(&self) -> u64

Get the end position

获取结束位置

§Returns

The end position of the range (exclusive)

§返回值

返回范围的结束位置(不包含)

Source

pub fn len(&self) -> u64

Get the length of the range in bytes

获取范围的长度(字节数)

Source

pub fn is_empty(&self) -> bool

Check if the range is empty

检查范围是否为空

Source

pub fn split_at_align_up(&self, pos: u64) -> SplitUpResult

Split the range at the given relative position with 4K upper alignment

在给定相对位置以4K上对齐方式拆分范围

The split point is calculated as align_up(start + pos).

分割点计算为 align_up(start + pos)

§Parameters
  • pos: Relative offset from the start of the range.
§Returns
  • SplitUpResult::Split { low, high }: Successfully split into [start, split) and [split, end)
  • SplitUpResult::Low: Only low range exists (split point >= end)
  • SplitUpResult::OutOfBounds: Position exceeds range length (pos > len)
§参数
  • pos: 从范围起始位置开始的相对偏移量。
§返回值
  • SplitUpResult::Split { low, high }: 成功拆分为 [start, split) 和 [split, end)
  • SplitUpResult::Low: 仅存在低范围(分割点 >= end)
  • SplitUpResult::OutOfBounds: 位置超出范围长度 (pos > len)
§Examples
let range = AllocatedRange::from_range_unchecked(0, 8192);
match range.split_at_align_up(100) {
    SplitUpResult::Split { low, high } => {
        assert_eq!(low.end(), 4096);  // Aligned up from 100
        assert_eq!(high.start(), 4096);
    }
    _ => panic!("expected split"),
}
Source

pub fn split_at_align_down(&self, pos: u64) -> SplitDownResult

Split the range at the given relative position with 4K lower alignment

在给定相对位置以4K下对齐方式拆分范围

The split point is calculated as align_down(start + pos).

分割点计算为 align_down(start + pos)

§Parameters
  • pos: Relative offset from the start of the range.
§Returns
  • SplitDownResult::Split { low, high }: Successfully split into [start, split) and [split, end)
  • SplitDownResult::High: Only high range exists (split point <= start)
  • SplitDownResult::OutOfBounds: Position exceeds range length (pos > len)
§参数
  • pos: 从范围起始位置开始的相对偏移量。
§返回值
  • SplitDownResult::Split { low, high }: 成功拆分为 [start, split) 和 [split, end)
  • SplitDownResult::High: 仅存在高范围(分割点 <= start)
  • SplitDownResult::OutOfBounds: 位置超出范围长度 (pos > len)
§Examples
let range = AllocatedRange::from_range_unchecked(0, 8192);
match range.split_at_align_down(5000) {
    SplitDownResult::Split { low, high } => {
        assert_eq!(low.end(), 4096);  // Aligned down from 5000
        assert_eq!(high.start(), 4096);
    }
    _ => panic!("expected split"),
}
Source

pub fn as_range_tuple(&self) -> (u64, u64)

Get the range as a tuple (start, end)

获取范围的元组表示 (start, end)

Returns half-open interval (start, end).

返回左闭右开区间 (start, end)

Source

pub fn as_range(&self) -> Range<u64>

Convert to standard Range

转换为标准 Range

Returns half-open interval start..end.

返回左闭右开区间 start..end

Trait Implementations§

Source§

impl Clone for AllocatedRange

Source§

fn clone(&self) -> AllocatedRange

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 AllocatedRange

Source§

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

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

impl From<AllocatedRange> for Range<u64>

Source§

fn from(range: AllocatedRange) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for AllocatedRange

Source§

fn eq(&self, other: &AllocatedRange) -> 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 AllocatedRange

Source§

impl Eq for AllocatedRange

Source§

impl StructuralPartialEq for AllocatedRange

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.