Enum iroh_blobs::util::MemOrFile

source ·
pub enum MemOrFile<M, F> {
    Mem(M),
    File(F),
}
Expand description

This is a general purpose Either, just like Result, except that the two cases are Mem for something that is in memory, and File for something that is somewhere external and only available via io.

Variants§

§

Mem(M)

We got it all in memory

§

File(F)

A file

Implementations§

source§

impl<M, F> MemOrFile<M, (F, u64)>
where M: AsRef<[u8]>,

Helper methods for a common way to use MemOrFile, where the memory part is something like a slice, and the file part is a tuple consisiting of path or file and size.

source

pub fn size(&self) -> u64

Get the size of the MemOrFile

source§

impl<M, F> MemOrFile<M, F>

source

pub fn as_ref(&self) -> MemOrFile<&M, &F>

Turn a reference to a MemOrFile into a MemOrFile of references

source

pub fn is_mem(&self) -> bool

True if this is a Mem

source

pub fn mem(&self) -> Option<&M>

Get the mem part

source

pub fn map_file<F2>(self, f: impl FnOnce(F) -> F2) -> MemOrFile<M, F2>

Map the file part of this MemOrFile

source

pub fn try_map_file<F2, E>( self, f: impl FnOnce(F) -> Result<F2, E> ) -> Result<MemOrFile<M, F2>, E>

Try to map the file part of this MemOrFile

source

pub fn map_mem<M2>(self, f: impl FnOnce(M) -> M2) -> MemOrFile<M2, F>

Map the memory part of this MemOrFile

Trait Implementations§

source§

impl<M: Debug, F: Debug> Debug for MemOrFile<M, F>

source§

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

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

impl<M: Default, F> Default for MemOrFile<M, F>

source§

fn default() -> Self

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

impl ReadAt for MemOrFile<Bytes, File>

source§

fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize>

Reads bytes from an offset in this source into a buffer, returning how many bytes were read. Read more
source§

fn read_exact_at(&self, pos: u64, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf from an offset. Read more
source§

impl Size for MemOrFile<Bytes, File>

source§

fn size(&self) -> Result<Option<u64>>

Get the size of this object, in bytes. Read more

Auto Trait Implementations§

§

impl<M, F> Freeze for MemOrFile<M, F>
where M: Freeze, F: Freeze,

§

impl<M, F> RefUnwindSafe for MemOrFile<M, F>

§

impl<M, F> Send for MemOrFile<M, F>
where M: Send, F: Send,

§

impl<M, F> Sync for MemOrFile<M, F>
where M: Sync, F: Sync,

§

impl<M, F> Unpin for MemOrFile<M, F>
where M: Unpin, F: Unpin,

§

impl<M, F> UnwindSafe for MemOrFile<M, F>
where M: UnwindSafe, F: 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T