pub trait FileStore:
Debug
+ Send
+ Sync {
// Required methods
fn intern(&self, path: &[u8]) -> Result<FileId, CfdpError>;
fn read_chunk(
&self,
path: FileId,
offset: u64,
length: u64,
buffer: &mut [u8],
) -> impl Future<Output = Result<usize, CfdpError>>;
fn write_chunk(
&mut self,
path: FileId,
offset: u64,
data: &[u8],
) -> impl Future<Output = Result<(), CfdpError>>;
fn file_size(
&self,
path: FileId,
) -> impl Future<Output = Result<u64, CfdpError>>;
// Provided method
fn calculate_checksum<H>(
&self,
file_id: FileId,
hasher: H,
) -> impl Future<Output = Result<u32, CfdpError>>
where H: CfdpChecksum { ... }
}Expand description
A trait defining the required asynchronous file operations for CFDP.
The methods return impl Future to support backends where I/O is non-blocking,
making the trait compatible with any async runtime.
Required Methods§
Sourcefn intern(&self, path: &[u8]) -> Result<FileId, CfdpError>
fn intern(&self, path: &[u8]) -> Result<FileId, CfdpError>
Interns a file path and returns a unique FileId.
Sourcefn read_chunk(
&self,
path: FileId,
offset: u64,
length: u64,
buffer: &mut [u8],
) -> impl Future<Output = Result<usize, CfdpError>>
fn read_chunk( &self, path: FileId, offset: u64, length: u64, buffer: &mut [u8], ) -> impl Future<Output = Result<usize, CfdpError>>
Reads a chunk of data from the source file at a given offset.
§Arguments
path: The path to the source file, as a string slice.offset: The byte offset from the beginning of the file to start reading.length: The maximum number of bytes to read.buffer: The buffer to write the read data into.
§Returns
A Future that resolves to a Result containing the number of bytes actually
read. This may be less than length if the end of the file is reached.
Sourcefn write_chunk(
&mut self,
path: FileId,
offset: u64,
data: &[u8],
) -> impl Future<Output = Result<(), CfdpError>>
fn write_chunk( &mut self, path: FileId, offset: u64, data: &[u8], ) -> impl Future<Output = Result<(), CfdpError>>
Writes a chunk of data to the destination file at a given offset.
The FileStore implementation is responsible for creating the file if it
does not exist.
§Arguments
path: The path to the destination file, as a string slice.offset: The byte offset from the beginning of the file to start writing.data: The slice of data to write.
§Returns
A Future that resolves to a Result indicating whether the write was successful.
Provided Methods§
Sourcefn calculate_checksum<H>(
&self,
file_id: FileId,
hasher: H,
) -> impl Future<Output = Result<u32, CfdpError>>where
H: CfdpChecksum,
fn calculate_checksum<H>(
&self,
file_id: FileId,
hasher: H,
) -> impl Future<Output = Result<u32, CfdpError>>where
H: CfdpChecksum,
Calculates the full-file checksum using the given hasher.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.