io_lifetimes

Trait AsFilelike

source
pub trait AsFilelike: AsFd {
    // Required methods
    fn as_filelike(&self) -> BorrowedFilelike<'_>;
    fn as_filelike_view<Target: FilelikeViewType>(
        &self,
    ) -> FilelikeView<'_, Target>;
}
Expand description

A portable trait to borrow a reference from an underlying filelike object.

This is a portability abstraction over Unix-like AsFd and Windows’ AsHandle. It also provides the as_filelike_view convenience function providing typed views.

Required Methods§

source

fn as_filelike(&self) -> BorrowedFilelike<'_>

Borrows the reference.

§Example
use std::fs::File;
use io_lifetimes::{AsFilelike, BorrowedFilelike};

let mut f = File::open("foo.txt")?;
let borrowed_filelike: BorrowedFilelike<'_> = f.as_filelike();
source

fn as_filelike_view<Target: FilelikeViewType>(&self) -> FilelikeView<'_, Target>

Return a borrowing view of a resource which dereferences to a &Target.

Note that Read or Write require &mut Target, but in some cases, such as File, Read and Write are implemented for &Target in addition to Target, and you can get a &mut &Target by doing &* on the resuting view, like this:

let v = f.as_filelike_view::<std::fs::File>();
(&*v).read(&mut buf).unwrap();

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: AsFd> AsFilelike for T