Struct memory_range::MemoryRange
source · pub struct MemoryRange { /* private fields */ }
Expand description
Represents a page-aligned byte range of memory.
This type has a stable Protobuf
representation, and can be directly used
in saved state.
Implementations§
source§impl MemoryRange
impl MemoryRange
sourcepub const MAX_ADDRESS: u64 = 18_446_744_073_709_547_520u64
pub const MAX_ADDRESS: u64 = 18_446_744_073_709_547_520u64
The maximum address that can be represented by a MemoryRange
.
sourcepub const fn new(range: Range<u64>) -> Self
pub const fn new(range: Range<u64>) -> Self
Returns a new range for the given guest address range.
Panics if the start or end are not 4KB aligned or if the start is after the end.
sourcepub const fn try_new(range: Range<u64>) -> Result<Self, InvalidMemoryRange>
pub const fn try_new(range: Range<u64>) -> Result<Self, InvalidMemoryRange>
Returns a new range for the given guest address range.
Returns None
if the start or end are not 4KB aligned or if the start
is after the end.
sourcepub fn bounding(range: Range<u64>) -> Self
pub fn bounding(range: Range<u64>) -> Self
Returns the smallest 4K-aligned range that contains the given address range.
Panics if the start is after the end or if the end address is in the last page of the 64-bit space.
sourcepub fn from_4k_gpn_range(range: Range<u64>) -> Self
pub fn from_4k_gpn_range(range: Range<u64>) -> Self
Returns a new range for the given guest 4KB page range.
Panics if the start is after the end or if the start address or end address overflow.
sourcepub fn start_4k_gpn(&self) -> u64
pub fn start_4k_gpn(&self) -> u64
The start address as a 4KB page number.
sourcepub fn end_4k_gpn(&self) -> u64
pub fn end_4k_gpn(&self) -> u64
The end address as a 4KB page number.
sourcepub fn page_count_4k(&self) -> u64
pub fn page_count_4k(&self) -> u64
The number of 4KB pages in the range.
sourcepub fn page_count_2m(&self) -> u64
pub fn page_count_2m(&self) -> u64
The number of 2MB pages in the range.
sourcepub fn aligned_subrange(&self, alignment: u64) -> Self
pub fn aligned_subrange(&self, alignment: u64) -> Self
Returns the largest range contained in this range whose start and end
are aligned to alignment
bytes. This may be the empty range.
Panics if alignment
is not a power of two.
sourcepub fn contains_addr(&self, addr: u64) -> bool
pub fn contains_addr(&self, addr: u64) -> bool
Returns whether self
contains the byte at addr
.
sourcepub fn offset_of(&self, addr: u64) -> Option<u64>
pub fn offset_of(&self, addr: u64) -> Option<u64>
Returns the byte offset of addr
within the range, if it is contained.
sourcepub fn intersection(&self, other: &Self) -> Self
pub fn intersection(&self, other: &Self) -> Self
Returns the intersection of self
and other
.
sourcepub fn split_at_offset(&self, offset: u64) -> (Self, Self)
pub fn split_at_offset(&self, offset: u64) -> (Self, Self)
Split the range at the given byte offset within the range.
Panics if offset
is not within the range or is not page-aligned.
Trait Implementations§
source§impl Clone for MemoryRange
impl Clone for MemoryRange
source§fn clone(&self) -> MemoryRange
fn clone(&self) -> MemoryRange
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MemoryRange
impl Debug for MemoryRange
source§impl DefaultEncoding for MemoryRange
impl DefaultEncoding for MemoryRange
source§type Encoding = TableEncoder
type Encoding = TableEncoder
source§impl DescribeTable for MemoryRange
impl DescribeTable for MemoryRange
source§const DESCRIPTION: MessageDescription<'static> = _
const DESCRIPTION: MessageDescription<'static> = _
source§impl Display for MemoryRange
impl Display for MemoryRange
source§impl From<MemoryRange> for Range<u64>
impl From<MemoryRange> for Range<u64>
source§fn from(range: MemoryRange) -> Self
fn from(range: MemoryRange) -> Self
source§impl Ord for MemoryRange
impl Ord for MemoryRange
source§fn cmp(&self, other: &MemoryRange) -> Ordering
fn cmp(&self, other: &MemoryRange) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for MemoryRange
impl PartialEq for MemoryRange
source§impl PartialOrd for MemoryRange
impl PartialOrd for MemoryRange
source§impl<'encoding, AnyR: 'static> StructDecodeMetadata<'encoding, AnyR> for MemoryRange
impl<'encoding, AnyR: 'static> StructDecodeMetadata<'encoding, AnyR> for MemoryRange
source§const DECODERS: &'static [ErasedDecoderEntry] = _
const DECODERS: &'static [ErasedDecoderEntry] = _
source§impl<AnyR: 'static> StructEncodeMetadata<AnyR> for MemoryRange
impl<AnyR: 'static> StructEncodeMetadata<AnyR> for MemoryRange
source§const ENCODERS: &'static [ErasedEncoderEntry] = _
const ENCODERS: &'static [ErasedEncoderEntry] = _
source§impl StructMetadata for MemoryRange
impl StructMetadata for MemoryRange
impl Copy for MemoryRange
impl Downcast<MemoryRange> for MemoryRange
impl Eq for MemoryRange
impl StructuralPartialEq for MemoryRange
Auto Trait Implementations§
impl Freeze for MemoryRange
impl RefUnwindSafe for MemoryRange
impl Send for MemoryRange
impl Sync for MemoryRange
impl Unpin for MemoryRange
impl UnwindSafe for MemoryRange
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> DescribedProtobuf for T
impl<T> DescribedProtobuf for T
source§const DESCRIPTION: MessageDescription<'static> = _
const DESCRIPTION: MessageDescription<'static> = _
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> MeshField for Twhere
T: DefaultEncoding + Any + Send + 'static,
<T as DefaultEncoding>::Encoding: FieldEncode<T, Resource> + for<'a> FieldDecode<'a, T, Resource> + Send + Sync,
impl<T> MeshField for Twhere
T: DefaultEncoding + Any + Send + 'static,
<T as DefaultEncoding>::Encoding: FieldEncode<T, Resource> + for<'a> FieldDecode<'a, T, Resource> + Send + Sync,
type Encoding = <T as DefaultEncoding>::Encoding
source§impl<T> MeshPayload for Twhere
T: DefaultEncoding + Any + Send + 'static,
<T as DefaultEncoding>::Encoding: MessageEncode<T, Resource> + for<'a> MessageDecode<'a, T, Resource> + FieldEncode<T, Resource> + for<'a> FieldDecode<'a, T, Resource> + Send + Sync,
impl<T> MeshPayload for Twhere
T: DefaultEncoding + Any + Send + 'static,
<T as DefaultEncoding>::Encoding: MessageEncode<T, Resource> + for<'a> MessageDecode<'a, T, Resource> + FieldEncode<T, Resource> + for<'a> FieldDecode<'a, T, Resource> + Send + Sync,
type Encoding = <T as DefaultEncoding>::Encoding
source§impl<T> Protobuf for Twhere
T: DefaultEncoding,
<T as DefaultEncoding>::Encoding: MessageEncode<T, NoResources> + for<'a> MessageDecode<'a, T, NoResources> + FieldEncode<T, NoResources> + for<'a> FieldDecode<'a, T, NoResources>,
impl<T> Protobuf for Twhere
T: DefaultEncoding,
<T as DefaultEncoding>::Encoding: MessageEncode<T, NoResources> + for<'a> MessageDecode<'a, T, NoResources> + FieldEncode<T, NoResources> + for<'a> FieldDecode<'a, T, NoResources>,
source§type Encoding = <T as DefaultEncoding>::Encoding
type Encoding = <T as DefaultEncoding>::Encoding
Self
.source§impl<T> SerializeMessage for Twhere
T: MeshPayload,
impl<T> SerializeMessage for Twhere
T: MeshPayload,
source§fn compute_message_size(&mut self, sizer: MessageSizer<'_>)
fn compute_message_size(&mut self, sizer: MessageSizer<'_>)
MessageEncode::compute_message_size
.source§fn write_message(self, writer: MessageWriter<'_, '_, Resource>)
fn write_message(self, writer: MessageWriter<'_, '_, Resource>)
MessageEncode::write_message
.