Skip to main content

CachedSource

Struct CachedSource 

Source
pub struct CachedSource { /* private fields */ }
Expand description

A block cache in front of a slow source (a host callback, a network reader). Readers issue many small reads for headers; this turns them into a few block-sized reads of the inner source. Reads of several blocks or more bypass the cache.

Implementations§

Source§

impl CachedSource

Source

pub const DEFAULT_BLOCK: u64

Default block size (64 KiB).

Source

pub const DEFAULT_CAPACITY: usize = 256

Default number of cached blocks (16 MiB with the default block size).

Source

pub fn new(inner: Arc<dyn ByteSource>, block: u64, capacity: usize) -> Self

Cache inner in blocks of block bytes, keeping at most capacity blocks.

Source

pub fn with_defaults(inner: Arc<dyn ByteSource>) -> Self

Cache inner with the default block size and capacity.

Trait Implementations§

Source§

impl ByteSource for CachedSource

Source§

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

Current length in bytes.
Source§

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

Read up to buf.len() bytes at offset; return how many were read (0 at or past the end). Like std::io::Read::read, a short read is allowed anywhere.
Source§

fn name(&self) -> String

A name for messages: the path of a local file, the name a host gave its buffer.
Source§

fn local_path(&self) -> Option<&Path>

The file on the local disk this source reads, if it is one.
Source§

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

Fill buf from offset, or fail with UnexpectedEof if the source ends first.
Source§

fn read_range(&self, offset: u64, len: usize) -> Result<SharedBytes>

Up to len bytes at offset (fewer at the end of the source). In-memory sources return a view of their buffer without copying; the default reads into a new buffer.
Source§

impl Debug for CachedSource

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.