MappedOption

Struct MappedOption 

Source
pub struct MappedOption<'a, T: MemoryMapped<'a>> { /* private fields */ }
Expand description

An optional immutable memory-mapped structure.

This is compatible with the serialization format of Option of the same type.

§Examples

use simple_sds_sbwt::serialize::{MappedOption, MappedSlice, MappingMode, MemoryMap, MemoryMapped, Serialize};
use simple_sds_sbwt::serialize;
use std::fs;

let some: Option<Vec<u64>> = Some(vec![123, 456, 789]);
let filename = serialize::temp_file_name("mapped-option");
serialize::serialize_to(&some, &filename);

let map = MemoryMap::new(&filename, MappingMode::ReadOnly).unwrap();
let mapped = MappedOption::<MappedSlice<u64>>::new(&map, 0).unwrap();
assert_eq!(mapped.unwrap().as_ref(), some.unwrap().as_slice());
drop(mapped); drop(map);

fs::remove_file(&filename).unwrap();

Implementations§

Source§

impl<'a, T: MemoryMapped<'a>> MappedOption<'a, T>

Source

pub fn is_some(&self) -> bool

Returns true if the option is a Some value.

Source

pub fn is_none(&self) -> bool

Returns true if the option is a None value.

Source

pub fn unwrap(&self) -> &T

Returns an immutable reference to the possibly contained value.

§Panics

Panics if the option is a None value.

Source

pub fn as_ref(&self) -> Option<&T>

Returns Option<&T> referencing the possibly contained value.

Trait Implementations§

Source§

impl<'a, T: Debug + MemoryMapped<'a>> Debug for MappedOption<'a, T>

Source§

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

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

impl<'a, T: MemoryMapped<'a>> MemoryMapped<'a> for MappedOption<'a, T>

Available on non-target_family=wasm only.
Source§

fn new(map: &'a MemoryMap, offset: usize) -> Result<Self>

Returns an immutable memory-mapped structure corresponding to an interval in the file. Read more
Source§

fn map_offset(&self) -> usize

Returns the starting offset in the file.
Source§

fn map_len(&self) -> usize

Returns the length of the interval corresponding to the structure.
Source§

impl<'a, T: PartialEq + MemoryMapped<'a>> PartialEq for MappedOption<'a, T>

Source§

fn eq(&self, other: &MappedOption<'a, T>) -> 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<'a, T: Eq + MemoryMapped<'a>> Eq for MappedOption<'a, T>

Source§

impl<'a, T: MemoryMapped<'a>> StructuralPartialEq for MappedOption<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for MappedOption<'a, T>
where T: Freeze,

§

impl<'a, T> RefUnwindSafe for MappedOption<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for MappedOption<'a, T>
where T: Send,

§

impl<'a, T> Sync for MappedOption<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for MappedOption<'a, T>
where T: Unpin,

§

impl<'a, T> UnwindSafe for MappedOption<'a, T>
where T: UnwindSafe,

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> 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, 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.