Struct memfile::MemFile [−][src]
A memory backed file that can have seals applied to it.
The struct implements AsRawFd
, IntoRawFd
and FromRawFd
.
When using FromRawFd::from_raw_fd
, you must ensure that the file descriptor is a valid memfd
.
Implementations
impl MemFile
[src]
pub fn create(name: &str, options: &CreateOptions) -> Result<Self>
[src]
Create a new memfd
with the given options.
The name
argument is purely for debugging purposes.
On Linux it shows up in /proc
, but it serves no other purpose.
In particular, multiple files can be created with the same name.
The close-on-exec flag is set on the created file descriptor.
If you want to pass it to a child process, you should use libc::dup2
or something similar after forking.
Disabling the close-on-exec flag before forking causes a race condition with other threads.
pub fn try_clone(&self) -> Result<Self>
[src]
Try to create a new MemFile
Createinstance that shares the same underlying file handle as the existing MemFile
instance.
Reads, writes, and seeks will affect both MemFile
instances simultaneously.
pub fn from_file<T: AsRawFd + IntoRawFd>(
file: T
) -> Result<Self, FromFdError<T>>
[src]
file: T
) -> Result<Self, FromFdError<T>>
Wrap an already-open file as MemFile
.
This function returns an error if the file was not created by memfd_create
.
If the function succeeds, the passed in file object is consumed and the returned MemFile
takes ownership of the file descriptor.
If the function fails, the original file object is included in the returned error.
pub fn set_len(&self, size: u64) -> Result<()>
[src]
Truncate or extend the underlying file, updating the size of this file to become size.
If the size is less than the current file's size, then the file will be shrunk. If it is greater than the current file's size, then the file will be extended to size and have all of the intermediate data filled in with 0s. The file's cursor isn't changed. In particular, if the cursor was at the end and the file is shrunk using this operation, the cursor will now be past the end.
pub fn get_seals(&self) -> Result<Seals>
[src]
Get the active seals of the file.
pub fn add_seal(&self, seal: Seal) -> Result<()>
[src]
Add a single seal to the file.
If you want to add multiple seals, you should prefer Self::add_seals
to reduce the number of syscalls.
This function will fail if the file was not created with sealing support,
if the file has already been sealed with Seal::Seal
,
or if you try to add Seal::Write
while a shared, writable memory mapping exists for the file.
Adding a seal that is already active is a no-op.
pub fn add_seals(&self, seals: Seals) -> Result<()>
[src]
Add multiple seals to the file.
This function will fail if the file was not created with sealing support,
if the file has already been sealed with Seal::Seal
,
or if you try to add Seal::Write
while a shared, writable memory mapping exists for the file.
Adding seals that are already active is a no-op.
Trait Implementations
impl AsRawFd for MemFile
[src]
impl Debug for MemFile
[src]
impl FileExt for MemFile
[src]
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
[src]
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>
[src]
pub fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<(), Error>
1.33.0[src]
pub fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<(), Error>
1.33.0[src]
impl FromRawFd for MemFile
[src]
unsafe fn from_raw_fd(fd: RawFd) -> Self
[src]
impl IntoRawFd for MemFile
[src]
fn into_raw_fd(self) -> RawFd
[src]
impl Read for MemFile
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
pub fn read_vectored(
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
1.36.0[src]
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
pub fn is_read_vectored(&self) -> bool
[src]
pub unsafe fn initializer(&self) -> Initializer
[src]
pub fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
1.0.0[src]
pub fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
pub fn bytes(self) -> Bytes<Self>
1.0.0[src]
pub fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
pub fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
impl Seek for MemFile
[src]
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
[src]
pub fn stream_len(&mut self) -> Result<u64, Error>
[src]
pub fn stream_position(&mut self) -> Result<u64, Error>
1.51.0[src]
impl Write for MemFile
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
pub fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>
1.36.0[src]
pub fn is_write_vectored(&self) -> bool
[src]
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
pub fn write_all_vectored(
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
[src]
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
1.0.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for MemFile
[src]
impl Send for MemFile
[src]
impl Sync for MemFile
[src]
impl Unpin for MemFile
[src]
impl UnwindSafe for MemFile
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,