Struct rarena_allocator::OpenOptions
source · pub struct OpenOptions { /* private fields */ }memmap and non-target_family="wasm" only.Expand description
Options for opening a file for memory mapping.
Implementations§
source§impl OpenOptions
impl OpenOptions
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a blank new set of options ready for configuration.
All options are initially set to false.
§Examples
use rarena_allocator::OpenOptions;
let mut options = OpenOptions::new();sourcepub fn read(self, read: bool) -> Self
pub fn read(self, read: bool) -> Self
Sets the option for read access.
This option, when true, will indicate that the file should be
read-able if opened.
§Examples
use rarena_allocator::OpenOptions;
let opts = OpenOptions::new().read(true);sourcepub fn write(self, write: bool) -> Self
pub fn write(self, write: bool) -> Self
Sets the option for write access.
This option, when true, will indicate that the file should be
write-able if opened.
If the file already exists, any write calls on it will overwrite its contents, without truncating it.
§Examples
use rarena_allocator::OpenOptions;
let opts = OpenOptions::new().write(true);sourcepub fn append(self, append: bool) -> Self
pub fn append(self, append: bool) -> Self
Sets the option for the append mode.
This option, when true, means that writes will append to a file instead
of overwriting previous contents.
Note that setting .write(true).append(true) has the same effect as
setting only .append(true).
For most filesystems, the operating system guarantees that all writes are atomic: no writes get mangled because another process writes at the same time.
One maybe obvious note when using append-mode: make sure that all data
that belongs together is written to the file in one operation. This
can be done by concatenating strings before passing them to write(),
or using a buffered writer (with a buffer of adequate size),
and calling flush() when the message is complete.
If a file is opened with both read and append access, beware that after
opening, and after every write, the position for reading may be set at the
end of the file. So, before writing, save the current position (using
seek(SeekFrom::Current(opts))), and restore it before the next read.
§Note
This function doesn’t create the file if it doesn’t exist. Use the
OpenOptions::create method to do so.
§Examples
use rarena_allocator::OpenOptions;
let opts = OpenOptions::new().append(true);sourcepub fn truncate(self, truncate: bool) -> Self
pub fn truncate(self, truncate: bool) -> Self
Sets the option for truncating a previous file.
If a file is successfully opened with this option set it will truncate the file to opts length if it already exists.
The file must be opened with write access for truncate to work.
§Examples
use rarena_allocator::OpenOptions;
let opts = OpenOptions::new().write(true).truncate(true);sourcepub fn create(self, size: Option<u32>) -> Self
pub fn create(self, size: Option<u32>) -> Self
Sets the option to create a new file, or open it if it already exists. If the file does not exist, it is created and set the lenght of the file to the given size.
In order for the file to be created, OpenOptions::write or
OpenOptions::append access must be used.
See also std::fs::write() for a simple function to
create a file with some given data.
§Examples
use rarena_allocator::OpenOptions;
let opts = OpenOptions::new().write(true).create(Some(1000));use rarena_allocator::OpenOptions;
let opts = OpenOptions::new().write(true).create(None);sourcepub fn create_new(self, size: Option<u32>) -> Self
pub fn create_new(self, size: Option<u32>) -> Self
Sets the option to create a new file and set the file length to the given value, failing if it already exists.
No file is allowed to exist at the target location, also no (dangling) symlink. In this way, if the call succeeds, the file returned is guaranteed to be new.
This option is useful because it is atomic. Otherwise between checking whether a file exists and creating a new one, the file may have been created by another process (a TOCTOU race condition / attack).
If .create_new(true) is set, .create() and .truncate() are
ignored.
The file must be opened with write or append access in order to create a new file.
§Examples
use rarena_allocator::OpenOptions;
let file = OpenOptions::new()
.write(true)
.create_new(Some(1000));use rarena_allocator::OpenOptions;
let opts = OpenOptions::new()
.write(true)
.create_new(None);Trait Implementations§
source§impl Clone for OpenOptions
impl Clone for OpenOptions
source§fn clone(&self) -> OpenOptions
fn clone(&self) -> OpenOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for OpenOptions
impl Debug for OpenOptions
source§impl Default for OpenOptions
impl Default for OpenOptions
source§impl From<OpenOptions> for OpenOptions
impl From<OpenOptions> for OpenOptions
source§fn from(opts: StdOpenOptions) -> Self
fn from(opts: StdOpenOptions) -> Self
Auto Trait Implementations§
impl Freeze for OpenOptions
impl RefUnwindSafe for OpenOptions
impl Send for OpenOptions
impl Sync for OpenOptions
impl Unpin for OpenOptions
impl UnwindSafe for OpenOptions
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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