Struct file_rw::FileWriter

source ·
pub struct FileWriter { /* private fields */ }
Expand description

FileWriter is a structure that allows writing to a file. It uses memory-mapped files for efficient file manipulation.

Implementations§

source§

impl FileWriter

source

pub fn open_file(file: File) -> Self

Opens a file and returns a FileWriter instance. It panics if it cannot get the path of the writer file.

source

pub fn open(path: impl AsRef<Path> + Send + Sync) -> Self

Opens a file in write mode and returns a FileWriter instance.

source

pub fn write(&mut self, bytes: impl AsRef<[u8]>) -> &Self

Writes bytes to the file. It replaces the entire content of the file with the provided bytes.

source

pub fn write_to_offset( &mut self, bytes: impl AsRef<[u8]>, offset: usize ) -> &Self

source

pub fn append(&mut self, bytes: impl AsRef<[u8]>) -> &Self

source

pub fn overwrite(&mut self, bytes: impl AsRef<[u8]>) -> &Self

source

pub fn bytes_mut(&mut self) -> &mut [u8]

source

pub fn bytes(&self) -> &[u8]

source

pub fn replace(&mut self, bytes: impl AsRef<[u8]>, offset: usize) -> &Self

Replaces a portion of the file content starting from the provided offset with the provided bytes.

source

pub fn find_replace( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]> ) -> &Self

Finds a sequence of bytes in the file and replaces it with another sequence of bytes. If the sequence to find is not found, it does nothing.

source

pub fn rfind_replace( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]> ) -> &Self

Finds the last occurrence of a slice of bytes in the file and replaces it with another slice of bytes.

source

pub fn rfind_replace_nth( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]>, n: usize ) -> &Self

Finds the nth occurrence of a slice of bytes in the file, in reverse order, and replaces it with another slice of bytes.

source

pub fn find_replace_nth( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]>, n: usize ) -> &Self

Finds the nth occurrence of a slice of bytes in the file and replaces it with another slice of bytes. If the slice to find is not found, no replacement occurs.

source

pub fn find_replace_all( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]> ) -> &Self

Finds all occurrences of a slice of bytes in the file and replaces them with another slice of bytes.

source

pub fn file(&mut self) -> File

Returns a File object that represents the file being written to.

source

pub fn len(&mut self) -> u64

source

pub fn set_len(&mut self, len: u64) -> &Self

source

pub fn extend_len_by(&mut self, len: u64) -> &Self

source

pub fn path(&mut self) -> &Box<dyn AsRef<Path> + Send + Sync>

Returns a reference to the path of the file being written to.

source

pub fn mmap(&mut self) -> &mut Box<MmapMut>

Returns a mutable reference to the memory-mapped file.

source

pub fn to_reader(&mut self) -> FileReader

Converts the FileWriter into a FileReader.

Trait Implementations§

source§

impl Debug for FileWriter

Writes “FileWriter({Path})” to the provided formatter.

source§

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

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

impl Display for FileWriter

Writes “FileWriter({path})” to the provided formatter.

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

§

type Output = T

Should always be Self
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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.