#[non_exhaustive]pub enum FileContent {
Owned(Vec<u8>),
Range(FileRange),
}Expand description
A regular file’s contents: either bytes in memory, or a range of a file on the host read at the moment it is placed.
The two coexist in one entry list, deliberately. A source that maps an on-host archive
yields handles; a caller that computes an entry’s bytes — rewriting one file of a tree
it is otherwise passing through — supplies them owned, in the same Vec<SourceEntry>.
§Why this is not just Vec<u8>
A format’s peak memory is otherwise the sum of every file it writes, because every file’s bytes are built before the first block is placed. A handle defers the bytes until the file is written, so the peak becomes the largest single file rather than the total.
The len is known without reading, which is what lets the model check a
file against the large_file feature — and name the offending path — before any bytes
are read.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Owned(Vec<u8>)
Bytes held in memory.
Range(FileRange)
A range of a file on the host, read when the content is placed.
Implementations§
Source§impl FileContent
impl FileContent
Sourcepub fn read(&self) -> Result<Cow<'_, [u8]>>
pub fn read(&self) -> Result<Cow<'_, [u8]>>
The file’s bytes, reading them from the host if they are not already in memory.
Bytes already held are borrowed, not copied: reading an Owned
entry costs nothing, so a caller that reads every entry in turn never holds two
copies of one file. Only a Range allocates, and only for as long
as the caller keeps what it returned.
§Errors
std::io::Error if the backing file cannot be read — including the case where
it is shorter than the range claims, which means the file changed after the source
that named it was built. An owned entry cannot fail.
Trait Implementations§
Source§impl Clone for FileContent
impl Clone for FileContent
Source§fn clone(&self) -> FileContent
fn clone(&self) -> FileContent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FileContent
impl Debug for FileContent
Source§impl From<&[u8]> for FileContent
impl From<&[u8]> for FileContent
Source§impl From<&str> for FileContent
impl From<&str> for FileContent
Source§impl From<FileRange> for FileContent
impl From<FileRange> for FileContent
Source§impl From<String> for FileContent
impl From<String> for FileContent
Source§impl PartialEq for FileContent
impl PartialEq for FileContent
Source§fn eq(&self, other: &FileContent) -> bool
fn eq(&self, other: &FileContent) -> bool
self and other values to be equal, and is used by ==.