# Trait std::os::unix::fs::FileExt 1.15.0 [−] [src]

    pub trait FileExt {
        fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>;
        fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>;
    }

This is supported on Unix only.

Unix-specific extensions to `File`.

## Required Methods

### `fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>`

This is supported on Unix only.

Reads a number of bytes starting from a given offset.

Returns the number of bytes read.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

Note that similar to `File::read`, it is not an error to return with a short read.

# Examples

    use std::os::unix::prelude::FileExt;
    use std::fs::File;

    let mut buf = [0u8; 8];
    let file = File::open("foo.txt")?;

    // We now read 8 bytes from the offset 10.
    let num_bytes_read = file.read_at(&mut buf, 10)?;
    println!("read {} bytes: {:?}", num_bytes_read, buf);Run

### `fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>`

This is supported on Unix only.

Writes a number of bytes starting from a given offset.

Returns the number of bytes written.

The offset is relative to the start of the file and thus independent from the current cursor.

The current file cursor is not affected by this function.

When writing beyond the end of the file, the file is appropriately extended and the intermediate bytes are initialized with the value 0.

Note that similar to `File::write`, it is not an error to return a short write.

# Examples

    use std::os::unix::prelude::FileExt;
    use std::fs::File;

    let file = File::open("foo.txt")?;

    // We now write at the offset 10.
    file.write_at(b"sushi", 10)?;Run

## Implementors

- [src]
  `impl FileExt for File`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)