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 positionend: 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
startis 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
impl AllocatedRange
Sourcepub fn split_at_align_up(&self, pos: u64) -> SplitUpResult
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"),
}Sourcepub fn split_at_align_down(&self, pos: u64) -> SplitDownResult
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"),
}Sourcepub fn as_range_tuple(&self) -> (u64, u64)
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)。
Trait Implementations§
Source§impl Clone for AllocatedRange
impl Clone for AllocatedRange
Source§fn clone(&self) -> AllocatedRange
fn clone(&self) -> AllocatedRange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more