[−][src]Struct symbolic_common::ByteView
A smart pointer for byte data.
This type can be used to uniformly access bytes that were created either from mmapping in a
path, a vector or a borrowed slice. A ByteView
dereferences into a &[u8]
and guarantees
random access to the underlying buffer or file.
A ByteView
can be constructed from borrowed slices, vectors or memory mapped from the file
system directly.
Example
The most common way to use ByteView
is to construct it from a file handle. This will own the
underlying file handle until the ByteView
is dropped:
use std::io::Write; use symbolic_common::ByteView; fn main() -> Result<(), std::io::Error> { let mut file = tempfile::tempfile()?; file.write_all(b"1234"); let view = ByteView::map_file(file)?; assert_eq!(view.as_slice(), b"1234"); Ok(()) }
Implementations
impl<'a> ByteView<'a>
[src]
pub fn from_cow(cow: Cow<'a, [u8]>) -> Self
[src]
Constructs a ByteView
from a Cow
.
Example
use std::borrow::Cow; use symbolic_common::ByteView; let cow = Cow::Borrowed(&b"1234"[..]); let view = ByteView::from_cow(cow);
pub fn from_slice(buffer: &'a [u8]) -> Self
[src]
Constructs a ByteView
from a byte slice.
Example
use symbolic_common::ByteView; let view = ByteView::from_slice(b"1234");
pub fn from_vec(buffer: Vec<u8>) -> Self
[src]
Constructs a ByteView
from a vector of bytes.
Example
use symbolic_common::ByteView; let vec = b"1234".to_vec(); let view = ByteView::from_vec(vec);
pub fn map_file(file: File) -> Result<Self, Error>
[src]
Constructs a ByteView
from an open file handle by memory mapping the file.
Example
use std::io::Write; use symbolic_common::ByteView; fn main() -> Result<(), std::io::Error> { let mut file = tempfile::tempfile()?; let view = ByteView::map_file(file)?; Ok(()) }
pub fn read<R: Read>(reader: R) -> Result<Self, Error>
[src]
Constructs a ByteView
from any std::io::Reader
.
Note: This currently consumes the entire reader and stores its data in an internal
buffer. Prefer open
when reading from the file system or from_slice
/ from_vec
for in-memory operations. This behavior might change in the future.
Example
use std::io::Cursor; use symbolic_common::ByteView; fn main() -> Result<(), std::io::Error> { let reader = Cursor::new(b"1234"); let view = ByteView::read(reader)?; Ok(()) }
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, Error>
[src]
Constructs a ByteView
from a file path by memory mapping the file.
Example
use symbolic_common::ByteView; fn main() -> Result<(), std::io::Error> { let view = ByteView::open("test.txt")?; Ok(()) }
pub fn as_slice(&self) -> &[u8]
[src]
Returns a slice of the underlying data.
Example
use symbolic_common::ByteView; let view = ByteView::from_slice(b"1234"); let data = view.as_slice();
Trait Implementations
impl<'_> AsRef<[u8]> for ByteView<'_>
[src]
impl<'a> Clone for ByteView<'a>
[src]
impl<'a> Debug for ByteView<'a>
[src]
impl<'_> Deref for ByteView<'_>
[src]
impl<'_> StableDeref for ByteView<'_>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for ByteView<'a>
impl<'a> Send for ByteView<'a>
impl<'a> Sync for ByteView<'a>
impl<'a> Unpin for ByteView<'a>
impl<'a> UnwindSafe for ByteView<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,