Struct gimli::read::EndianReader [−][src]
pub struct EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug, { /* fields omitted */ }
An easy way to define a custom Reader
implementation with a reference to a
generic buffer of bytes and an associated endianity.
Note that the whole original buffer is kept alive in memory even if there is
only one reader that references only a handful of bytes from that original
buffer. That is, EndianReader
will not do any copying, moving, or
compacting in order to free up unused regions of the original buffer. If you
require this kind of behavior, it is up to you to implement Reader
directly by-hand.
Example
Say you have an mmap
ed file that you want to serve as a gimli::Reader
.
You can wrap that mmap
ed file up in a MmapFile
type and use
EndianReader<Rc<MmapFile>>
or EndianReader<Arc<MmapFile>>
as readers as
long as MmapFile
dereferences to the underlying [u8]
data.
use std::io; use std::ops::Deref; use std::path::Path; use std::slice; use std::sync::Arc; /// A type that represents an `mmap`ed file. #[derive(Debug)] pub struct MmapFile { ptr: *const u8, len: usize, } impl MmapFile { pub fn new(path: &Path) -> io::Result<MmapFile> { // Call `mmap` and check for errors and all that... } } impl Drop for MmapFile { fn drop(&mut self) { // Call `munmap` to clean up after ourselves... } } // And `MmapFile` can deref to a slice of the `mmap`ed region of memory. impl Deref for MmapFile { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { slice::from_raw_parts(self.ptr, self.len) } } } /// A type that represents a shared `mmap`ed file. #[derive(Debug, Clone)] pub struct ArcMmapFile(Arc<MmapFile>); // And `ArcMmapFile` can deref to a slice of the `mmap`ed region of memory. impl Deref for ArcMmapFile { type Target = [u8]; fn deref(&self) -> &[u8] { &self.0 } } // These are both valid for any `Rc` or `Arc`. unsafe impl gimli::StableDeref for ArcMmapFile {} unsafe impl gimli::CloneStableDeref for ArcMmapFile {} /// A `gimli::Reader` that is backed by an `mmap`ed file! pub type MmapFileReader<Endian> = gimli::EndianReader<Endian, ArcMmapFile>;
Implementations
impl<Endian, T> EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian, T> EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]impl<Endian, T> EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian, T> EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]Range Methods
Unfortunately, std::ops::Index
must return a reference, so we can’t
implement Index<Range<usize>>
to return a new EndianReader
the way we
would like to. Instead, we abandon fancy indexing operators and have these
plain old methods.
pub fn range(&self, idx: Range<usize>) -> EndianReader<Endian, T>
[src]
Take the given start..end
range of the underlying buffer and return a
new EndianReader
.
use gimli::{EndianReader, LittleEndian}; use std::sync::Arc; let buf = Arc::<[u8]>::from(&[0x01, 0x02, 0x03, 0x04][..]); let reader = EndianReader::new(buf.clone(), LittleEndian); assert_eq!(reader.range(1..3), EndianReader::new(&buf[1..3], LittleEndian));
Panics
Panics if the range is out of bounds.
pub fn range_from(&self, idx: RangeFrom<usize>) -> EndianReader<Endian, T>
[src]
Take the given start..
range of the underlying buffer and return a new
EndianReader
.
use gimli::{EndianReader, LittleEndian}; use std::sync::Arc; let buf = Arc::<[u8]>::from(&[0x01, 0x02, 0x03, 0x04][..]); let reader = EndianReader::new(buf.clone(), LittleEndian); assert_eq!(reader.range_from(2..), EndianReader::new(&buf[2..], LittleEndian));
Panics
Panics if the range is out of bounds.
pub fn range_to(&self, idx: RangeTo<usize>) -> EndianReader<Endian, T>
[src]
Take the given ..end
range of the underlying buffer and return a new
EndianReader
.
use gimli::{EndianReader, LittleEndian}; use std::sync::Arc; let buf = Arc::<[u8]>::from(&[0x01, 0x02, 0x03, 0x04][..]); let reader = EndianReader::new(buf.clone(), LittleEndian); assert_eq!(reader.range_to(..3), EndianReader::new(&buf[..3], LittleEndian));
Panics
Panics if the range is out of bounds.
Trait Implementations
impl<Endian: Clone, T: Clone> Clone for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian: Clone, T: Clone> Clone for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]fn clone(&self) -> EndianReader<Endian, T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Endian: Debug, T: Debug> Debug for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian: Debug, T: Debug> Debug for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]impl<Endian, T> Deref for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian, T> Deref for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]impl<Endian: Hash, T: Hash> Hash for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian: Hash, T: Hash> Hash for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]impl<Endian, T> Index<RangeFrom<usize>> for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian, T> Index<RangeFrom<usize>> for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]impl<Endian, T> Index<usize> for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian, T> Index<usize> for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]impl<Endian, T1, T2> PartialEq<EndianReader<Endian, T2>> for EndianReader<Endian, T1> where
Endian: Endianity,
T1: CloneStableDeref<Target = [u8]> + Debug,
T2: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian, T1, T2> PartialEq<EndianReader<Endian, T2>> for EndianReader<Endian, T1> where
Endian: Endianity,
T1: CloneStableDeref<Target = [u8]> + Debug,
T2: CloneStableDeref<Target = [u8]> + Debug,
[src]impl<Endian, T> Reader for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
impl<Endian, T> Reader for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]type Endian = Endian
The endianity of bytes that are read.
type Offset = usize
The type used for offsets and lengths.
fn endian(&self) -> Endian
[src]
fn len(&self) -> usize
[src]
fn empty(&mut self)
[src]
fn truncate(&mut self, len: usize) -> Result<()>
[src]
fn offset_from(&self, base: &EndianReader<Endian, T>) -> usize
[src]
fn offset_id(&self) -> ReaderOffsetId
[src]
fn lookup_offset_id(&self, id: ReaderOffsetId) -> Option<Self::Offset>
[src]
fn find(&self, byte: u8) -> Result<usize>
[src]
fn skip(&mut self, len: usize) -> Result<()>
[src]
fn split(&mut self, len: usize) -> Result<Self>
[src]
fn to_slice(&self) -> Result<Cow<'_, [u8]>>
[src]
fn to_string(&self) -> Result<Cow<'_, str>>
[src]
fn to_string_lossy(&self) -> Result<Cow<'_, str>>
[src]
fn read_slice(&mut self, buf: &mut [u8]) -> Result<()>
[src]
fn read_u8_array<A>(&mut self) -> Result<A> where
A: Sized + Default + AsMut<[u8]>,
[src]
A: Sized + Default + AsMut<[u8]>,
fn is_empty(&self) -> bool
[src]
fn read_u8(&mut self) -> Result<u8>
[src]
fn read_i8(&mut self) -> Result<i8>
[src]
fn read_u16(&mut self) -> Result<u16>
[src]
fn read_i16(&mut self) -> Result<i16>
[src]
fn read_u32(&mut self) -> Result<u32>
[src]
fn read_i32(&mut self) -> Result<i32>
[src]
fn read_u64(&mut self) -> Result<u64>
[src]
fn read_i64(&mut self) -> Result<i64>
[src]
fn read_f32(&mut self) -> Result<f32>
[src]
fn read_f64(&mut self) -> Result<f64>
[src]
fn read_uint(&mut self, n: usize) -> Result<u64>
[src]
fn read_null_terminated_slice(&mut self) -> Result<Self>
[src]
fn read_uleb128(&mut self) -> Result<u64>
[src]
fn read_uleb128_u16(&mut self) -> Result<u16>
[src]
fn read_sleb128(&mut self) -> Result<i64>
[src]
fn read_initial_length(&mut self) -> Result<(Self::Offset, Format)>
[src]
fn read_address(&mut self, address_size: u8) -> Result<u64>
[src]
fn read_word(&mut self, format: Format) -> Result<Self::Offset>
[src]
fn read_length(&mut self, format: Format) -> Result<Self::Offset>
[src]
fn read_offset(&mut self, format: Format) -> Result<Self::Offset>
[src]
fn read_sized_offset(&mut self, size: u8) -> Result<Self::Offset>
[src]
impl<Endian: Copy, T: Copy> Copy for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
impl<Endian, T> Eq for EndianReader<Endian, T> where
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
[src]
Endian: Endianity,
T: CloneStableDeref<Target = [u8]> + Debug,
Auto Trait Implementations
impl<Endian, T> RefUnwindSafe for EndianReader<Endian, T> where
Endian: RefUnwindSafe,
T: RefUnwindSafe,
Endian: RefUnwindSafe,
T: RefUnwindSafe,
impl<Endian, T> Send for EndianReader<Endian, T> where
Endian: Send,
T: Send,
Endian: Send,
T: Send,
impl<Endian, T> Sync for EndianReader<Endian, T> where
Endian: Sync,
T: Sync,
Endian: Sync,
T: Sync,
impl<Endian, T> Unpin for EndianReader<Endian, T> where
Endian: Unpin,
T: Unpin,
Endian: Unpin,
T: Unpin,
impl<Endian, T> UnwindSafe for EndianReader<Endian, T> where
Endian: UnwindSafe,
T: UnwindSafe,
Endian: UnwindSafe,
T: UnwindSafe,