Trait positioned_io::Size

source ·
pub trait Size {
    // Required method
    fn size(&self) -> Result<Option<u64>>;
}
Expand description

Trait to get the size in bytes of an I/O object.

Implementing this for a types with ReadAt or WriteAt makes it easier for users to predict whether they will read past end-of-file. However, it may not be possible to implement for certain readers or writers that have unknown size.

Examples

use std::fs::File;
use positioned_io::Size;

let file = File::open("tests/pi.txt")?;
let size = file.size()?;
assert_eq!(size, Some(1000002));

// some special files do not have a known size
let file = File::open("/dev/stdin")?;
let size = file.size()?;
assert_eq!(size, None);

Required Methods§

source

fn size(&self) -> Result<Option<u64>>

Get the size of this object, in bytes.

This function may return Ok(None) if the size is unknown, for example for pipes.

Implementations on Foreign Types§

source§

impl Size for Vec<u8>

source§

fn size(&self) -> Result<Option<u64>>

source§

impl Size for File

source§

fn size(&self) -> Result<Option<u64>>

source§

impl<'a> Size for &'a [u8]

source§

fn size(&self) -> Result<Option<u64>>

source§

impl<'a> Size for &'a mut [u8]

source§

fn size(&self) -> Result<Option<u64>>

source§

impl<'a, S: Size + ?Sized> Size for &'a S

source§

fn size(&self) -> Result<Option<u64>>

source§

impl<'a, S: Size + ?Sized> Size for &'a mut S

source§

fn size(&self) -> Result<Option<u64>>

source§

impl<'a, S: Size> Size for &'a RefCell<S>

source§

fn size(&self) -> Result<Option<u64>>

source§

impl<S: Size + ?Sized> Size for Box<S>

source§

fn size(&self) -> Result<Option<u64>>

Implementors§