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
impl CachedSource
Sourcepub const DEFAULT_BLOCK: u64
pub const DEFAULT_BLOCK: u64
Default block size (64 KiB).
Sourcepub const DEFAULT_CAPACITY: usize = 256
pub const DEFAULT_CAPACITY: usize = 256
Default number of cached blocks (16 MiB with the default block size).
Sourcepub fn new(inner: Arc<dyn ByteSource>, block: u64, capacity: usize) -> Self
pub fn new(inner: Arc<dyn ByteSource>, block: u64, capacity: usize) -> Self
Cache inner in blocks of block bytes, keeping at most capacity blocks.
Sourcepub fn with_defaults(inner: Arc<dyn ByteSource>) -> Self
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
impl ByteSource for CachedSource
Source§fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize>
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
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>
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<()>
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>
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.Auto Trait Implementations§
impl !Freeze for CachedSource
impl !RefUnwindSafe for CachedSource
impl !UnwindSafe for CachedSource
impl Send for CachedSource
impl Sync for CachedSource
impl Unpin for CachedSource
impl UnsafeUnpin for CachedSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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