Struct openssh_sftp_client::file::OpenOptions
source · [−]pub struct OpenOptions<'s> { /* private fields */ }
Expand description
Options and flags which can be used to configure how a file is opened.
Implementations
sourceimpl<'s> OpenOptions<'s>
impl<'s> OpenOptions<'s>
sourcepub fn read(&mut self, read: bool) -> &mut Self
pub fn read(&mut self, read: bool) -> &mut Self
Sets the option for read access.
This option, when true, will indicate that the file should be read-able if opened.
sourcepub fn write(&mut self, write: bool) -> &mut Self
pub fn write(&mut self, write: bool) -> &mut 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.
sourcepub fn append(&mut self, append: bool) -> &mut Self
pub fn append(&mut self, append: bool) -> &mut 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.
Note that this function doesn’t create the file if it doesn’t exist.
Use the OpenOptions::create
method to do so.
sourcepub fn truncate(&mut self, truncate: bool) -> &mut Self
pub fn truncate(&mut self, truncate: bool) -> &mut 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 0
length if it already exists.
Only take effect if OpenOptions::create
is set to true
.
sourcepub fn create(&mut self, create: bool) -> &mut Self
pub fn create(&mut self, create: bool) -> &mut Self
Sets the option to create a new file, or open it if it already exists.
sourcepub fn create_new(&mut self, create_new: bool) -> &mut Self
pub fn create_new(&mut self, create_new: bool) -> &mut Self
Sets the option to create a new file, 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.
Trait Implementations
sourceimpl<'s> Clone for OpenOptions<'s>
impl<'s> Clone for OpenOptions<'s>
sourcefn clone(&self) -> OpenOptions<'s>
fn clone(&self) -> OpenOptions<'s>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'s> Debug for OpenOptions<'s>
impl<'s> Debug for OpenOptions<'s>
impl<'s> Copy for OpenOptions<'s>
Auto Trait Implementations
impl<'s> !RefUnwindSafe for OpenOptions<'s>
impl<'s> Send for OpenOptions<'s>
impl<'s> Sync for OpenOptions<'s>
impl<'s> Unpin for OpenOptions<'s>
impl<'s> !UnwindSafe for OpenOptions<'s>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more