Struct ArrayMemoryRegion

Source
pub struct ArrayMemoryRegion<const SIZE: usize> { /* private fields */ }
Expand description

A memory region that is backed by a stack allocated array

Implementations§

Source§

impl<const SIZE: usize> ArrayMemoryRegion<SIZE>

Source

pub fn new(start_address: u64, data: ArrayVec<u8, SIZE>) -> Self

Creates a new memory region starting at the given address with the given data

Source

pub fn bytes(&self) -> MemoryRegionIterator<'_>

Get a byte iterator for this region.

This iterator can be used to store the region as bytes or to stream over a network. The iterated bytes include the length so that if you use the FromIterator implementation, it consumes only the bytes that are part of the collection. This means you can chain multiple of these iterators after each other.

use arrayvec::ArrayVec;
use stackdump_core::memory_region::{ArrayMemoryRegion, MemoryRegion};

let region1 = ArrayMemoryRegion::<4>::new(0, ArrayVec::from([1, 2, 3, 4]));
let region2 = ArrayMemoryRegion::<4>::new(100, ArrayVec::from([5, 6, 7, 8]));

let mut intermediate_buffer = Vec::new();

intermediate_buffer.extend(region1.bytes());
intermediate_buffer.extend(region2.bytes());

let mut intermediate_iter = intermediate_buffer.iter();

assert_eq!(region1, ArrayMemoryRegion::<4>::from_iter(&mut intermediate_iter));
assert_eq!(region2, ArrayMemoryRegion::<4>::from_iter(&mut intermediate_iter));
Source

pub unsafe fn copy_from_memory(&mut self, data_ptr: *const u8, data_len: usize)

Clears the existing memory data and copies the new data from the given pointer

If the data_len is greater than the capacity of this memory region, then this function will panic.

§Safety

The entire block of memory from data_ptr .. data_ptr + data_len must be readable. (A memcpy must be possible with the pointer as source)

Trait Implementations§

Source§

impl<const SIZE: usize> Clone for ArrayMemoryRegion<SIZE>

Source§

fn clone(&self) -> ArrayMemoryRegion<SIZE>

Returns a copy 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<const SIZE: usize> Debug for ArrayMemoryRegion<SIZE>

Source§

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

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

impl<const SIZE: usize> Default for ArrayMemoryRegion<SIZE>

Source§

fn default() -> ArrayMemoryRegion<SIZE>

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

impl<'de, const SIZE: usize> Deserialize<'de> for ArrayMemoryRegion<SIZE>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, const SIZE: usize> FromIterator<&'a u8> for ArrayMemoryRegion<SIZE>

Source§

fn from_iter<T: IntoIterator<Item = &'a u8>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<const SIZE: usize> FromIterator<u8> for ArrayMemoryRegion<SIZE>

Source§

fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<const SIZE: usize> MemoryRegion for ArrayMemoryRegion<SIZE>

Source§

fn read(&self, index: Range<u64>) -> Result<Option<Vec<u8>>, MemoryReadError>

Returns the slice of memory that can be found at the given address_range. If the given address range is not fully within the captured region, then None is returned.
Source§

fn read_u8(&self, address: u64) -> Result<Option<u8>, MemoryReadError>

Reads a byte from the given address if it is present in the region
Source§

fn read_u32( &self, address: u64, endianness: RunTimeEndian, ) -> Result<Option<u32>, MemoryReadError>

Reads a u32 from the given address if it is present in the region
Source§

impl<const SIZE: usize> PartialEq for ArrayMemoryRegion<SIZE>

Source§

fn eq(&self, other: &ArrayMemoryRegion<SIZE>) -> 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<const SIZE: usize> Serialize for ArrayMemoryRegion<SIZE>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const SIZE: usize> Eq for ArrayMemoryRegion<SIZE>

Source§

impl<const SIZE: usize> StructuralPartialEq for ArrayMemoryRegion<SIZE>

Auto Trait Implementations§

§

impl<const SIZE: usize> Freeze for ArrayMemoryRegion<SIZE>

§

impl<const SIZE: usize> RefUnwindSafe for ArrayMemoryRegion<SIZE>

§

impl<const SIZE: usize> Send for ArrayMemoryRegion<SIZE>

§

impl<const SIZE: usize> Sync for ArrayMemoryRegion<SIZE>

§

impl<const SIZE: usize> Unpin for ArrayMemoryRegion<SIZE>

§

impl<const SIZE: usize> UnwindSafe for ArrayMemoryRegion<SIZE>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,