io_lifetimes

Trait FromFilelike

Source
pub trait FromFilelike: From<OwnedFd> {
    // Required methods
    fn from_filelike(owned: OwnedFilelike) -> Self;
    fn from_into_filelike<Owned: IntoFilelike>(owned: Owned) -> Self;
}
Expand description

A portable trait to express the ability to construct an object from a filelike object.

This is a portability abstraction over Unix-like From<OwnedFd> and Windows’ From<OwnedHandle>. It also provides the from_into_filelike convenience function providing simplified from+into conversions.

Required Methods§

Source

fn from_filelike(owned: OwnedFilelike) -> Self

Constructs a new instance of Self from the given filelike object.

§Example
use std::fs::File;
use io_lifetimes::{FromFilelike, IntoFilelike, OwnedFilelike};

let f = File::open("foo.txt")?;
let owned_filelike: OwnedFilelike = f.into_filelike();
let f = File::from_filelike(owned_filelike);
Source

fn from_into_filelike<Owned: IntoFilelike>(owned: Owned) -> Self

Constructs a new instance of Self from the given filelike object converted from into_owned.

§Example
use std::fs::File;
use io_lifetimes::{FromFilelike, IntoFilelike};

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§