1.0.0[][src]Trait kompact::From

pub trait From<T> {
    fn from(T) -> Self;
}

Used to do value-to-value conversions while consuming the input value. It is the reciprocal of Into.

One should always prefer implementing From over Into because implementing From automatically provides one with a implementation of Into thanks to the blanket implementation in the standard library.

Only implement Into if a conversion to a type outside the current crate is required. From cannot do these type of conversions because of Rust's orphaning rules. See Into for more details.

Prefer using Into over using From when specifying trait bounds on a generic function. This way, types that directly implement Into can be used as arguments as well.

The From is also very useful when performing error handling. When constructing a function that is capable of failing, the return type will generally be of the form Result<T, E>. The From trait simplifies error handling by allowing a function to return a single error type that encapsulate multiple error types. See the "Examples" section and the book for more details.

Note: This trait must not fail. If the conversion can fail, use TryFrom.

Generic Implementations

  • [From<T>] for U implies Into<U> for T
  • From is reflexive, which means that From<T> for T is implemented

Examples

String implements From<&str>:

An explicit conversion from a &str to a String is done as follows:

let string = "hello".to_string();
let other_string = String::from("hello");

assert_eq!(string, other_string);

While performing error handling it is often useful to implement From for your own error type. By converting underlying error types to our own custom error type that encapsulates the underlying error type, we can return a single error type without losing information on the underlying cause. The '?' operator automatically converts the underlying error type to our custom error type by calling Into<CliError>::into which is automatically provided when implementing From. The compiler then infers which implementation of Into should be used.

use std::fs;
use std::io;
use std::num;

enum CliError {
    IoError(io::Error),
    ParseError(num::ParseIntError),
}

impl From<io::Error> for CliError {
    fn from(error: io::Error) -> Self {
        CliError::IoError(error)
    }
}

impl From<num::ParseIntError> for CliError {
    fn from(error: num::ParseIntError) -> Self {
        CliError::ParseError(error)
    }
}

fn open_and_parse_file(file_name: &str) -> Result<i32, CliError> {
    let mut contents = fs::read_to_string(&file_name)?;
    let num: i32 = contents.trim().parse()?;
    Ok(num)
}

Required methods

fn from(T) -> Self

Performs the conversion.

Loading content...

Implementations on Foreign Types

impl<'a> From<&'a OsStr> for Cow<'a, OsStr>[src]

impl From<[u16; 8]> for IpAddr[src]

fn from(segments: [u16; 8]) -> IpAddr[src]

Creates an IpAddr::V6 from an eight element 16-bit array.

Examples

use std::net::{IpAddr, Ipv6Addr};

let addr = IpAddr::from([
    525u16, 524u16, 523u16, 522u16,
    521u16, 520u16, 519u16, 518u16,
]);
assert_eq!(
    IpAddr::V6(Ipv6Addr::new(
        0x20d, 0x20c,
        0x20b, 0x20a,
        0x209, 0x208,
        0x207, 0x206
    )),
    addr
);

impl<I> From<(I, u16)> for SocketAddr where
    I: Into<IpAddr>, 
[src]

fn from(pieces: (I, u16)) -> SocketAddr[src]

Converts a tuple struct (Into<[IpAddr]>, u16) into a [SocketAddr].

This conversion creates a [SocketAddr::V4] for a [IpAddr::V4] and creates a [SocketAddr::V6] for a [IpAddr::V6].

u16 is treated as port of the newly created [SocketAddr].

impl From<[u8; 4]> for Ipv4Addr[src]

fn from(octets: [u8; 4]) -> Ipv4Addr[src]

Examples

use std::net::Ipv4Addr;

let addr = Ipv4Addr::from([13u8, 12u8, 11u8, 10u8]);
assert_eq!(Ipv4Addr::new(13, 12, 11, 10), addr);

impl From<ErrorKind> for Error[src]

Intended for use for errors not exposed to the user, where allocating onto the heap (for normal construction via Error::new) is too costly.

fn from(kind: ErrorKind) -> Error[src]

Converts an ErrorKind into an Error.

This conversion allocates a new error with a simple representation of error kind.

Examples

use std::io::{Error, ErrorKind};

let not_found = ErrorKind::NotFound;
let error = Error::from(not_found);
assert_eq!("entity not found", format!("{}", error));

impl From<File> for Stdio[src]

fn from(file: File) -> Stdio[src]

Converts a File into a Stdio

Examples

File will be converted to Stdio using Stdio::from under the hood.

use std::fs::File;
use std::process::Command;

// With the `foo.txt` file containing `Hello, world!"
let file = File::open("foo.txt").unwrap();

let reverse = Command::new("rev")
    .stdin(file)  // Implicit File conversion into a Stdio
    .output()
    .expect("failed reverse command");

assert_eq!(reverse.stdout, b"!dlrow ,olleH");

impl<'a, E> From<E> for Box<dyn Error + 'a + Sync + Send> where
    E: 'a + Error + Send + Sync
[src]

fn from(err: E) -> Box<dyn Error + 'a + Sync + Send>[src]

Converts a type of [Error] + Send + Sync into a box of dyn [Error] + Send + Sync.

Examples

use std::error::Error;
use std::fmt;
use std::mem;

#[derive(Debug)]
struct AnError;

impl fmt::Display for AnError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f , "An error")
    }
}

impl Error for AnError {
    fn description(&self) -> &str {
        "Description of an error"
    }
}

unsafe impl Send for AnError {}

unsafe impl Sync for AnError {}

let an_error = AnError;
assert!(0 == mem::size_of_val(&an_error));
let a_boxed_error = Box::<Error + Send + Sync>::from(an_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

impl From<SocketAddrV6> for SocketAddr[src]

fn from(sock6: SocketAddrV6) -> SocketAddr[src]

Converts a [SocketAddrV6] into a [SocketAddr::V6].

impl From<u128> for Ipv6Addr[src]

fn from(ip: u128) -> Ipv6Addr[src]

Convert a host byte order u128 into an Ipv6Addr.

Examples

use std::net::Ipv6Addr;

let addr = Ipv6Addr::from(0x102030405060708090A0B0C0D0E0F00D_u128);
assert_eq!(
    Ipv6Addr::new(
        0x1020, 0x3040, 0x5060, 0x7080,
        0x90A0, 0xB0C0, 0xD0E0, 0xF00D,
    ),
    addr);

impl From<PathBuf> for Rc<Path>[src]

fn from(s: PathBuf) -> Rc<Path>[src]

Converts a Path into a Rc by copying the Path data into a new Rc buffer.

impl<'a> From<Cow<'a, str>> for Box<dyn Error + 'static>[src]

fn from(err: Cow<'a, str>) -> Box<dyn Error + 'static>[src]

Converts a [Cow] into a box of dyn [Error].

Examples

use std::error::Error;
use std::mem;
use std::borrow::Cow;

let a_cow_str_error = Cow::from("a str error");
let a_boxed_error = Box::<Error>::from(a_cow_str_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))

impl<'a> From<&'a CStr> for Cow<'a, CStr>[src]

impl<W> From<IntoInnerError<W>> for Error[src]

impl From<ChildStdout> for Stdio[src]

fn from(child: ChildStdout) -> Stdio[src]

Converts a ChildStdout into a Stdio

Examples

ChildStdout will be converted to Stdio using Stdio::from under the hood.

use std::process::{Command, Stdio};

let hello = Command::new("echo")
    .arg("Hello, world!")
    .stdout(Stdio::piped())
    .spawn()
    .expect("failed echo command");

let reverse = Command::new("rev")
    .stdin(hello.stdout.unwrap())  // Converted into a Stdio here
    .output()
    .expect("failed reverse command");

assert_eq!(reverse.stdout, b"!dlrow ,olleH\n");

impl<'a> From<&'a CString> for Cow<'a, CStr>[src]

impl<'a, '_> From<&'_ str> for Box<dyn Error + 'a + Sync + Send>[src]

fn from(err: &str) -> Box<dyn Error + 'a + Sync + Send>[src]

Converts a str into a box of dyn [Error] + Send + Sync.

Examples

use std::error::Error;
use std::mem;

let a_str_error = "a str error";
let a_boxed_error = Box::<Error + Send + Sync>::from(a_str_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

impl From<RecvError> for RecvTimeoutError[src]

impl<T> From<SendError<T>> for TrySendError<T>[src]

impl<T> From<T> for Mutex<T>[src]

fn from(t: T) -> Mutex<T>[src]

Creates a new mutex in an unlocked state ready for use. This is equivalent to [Mutex::new].

impl<'_> From<&'_ CStr> for Arc<CStr>[src]

impl From<[u8; 4]> for IpAddr[src]

fn from(octets: [u8; 4]) -> IpAddr[src]

Creates an IpAddr::V4 from a four element byte array.

Examples

use std::net::{IpAddr, Ipv4Addr};

let addr = IpAddr::from([13u8, 12u8, 11u8, 10u8]);
assert_eq!(IpAddr::V4(Ipv4Addr::new(13, 12, 11, 10)), addr);

impl<T> From<T> for RwLock<T>[src]

fn from(t: T) -> RwLock<T>[src]

Creates a new instance of an RwLock<T> which is unlocked. This is equivalent to [RwLock::new].

impl From<OsString> for Box<OsStr>[src]

fn from(s: OsString) -> Box<OsStr>[src]

Converts a OsString into a Box<OsStr> without copying or allocating.

impl From<Box<Path>> for PathBuf[src]

fn from(boxed: Box<Path>) -> PathBuf[src]

Converts a Box<Path> into a PathBuf

This conversion does not allocate or copy memory.

impl From<PathBuf> for Box<Path>[src]

fn from(p: PathBuf) -> Box<Path>[src]

Converts a PathBuf into a Box<Path>

This conversion currently should not allocate memory, but this behavior is not guaranteed on all platforms or in all future versions.

impl From<[u8; 16]> for IpAddr[src]

fn from(octets: [u8; 16]) -> IpAddr[src]

Creates an IpAddr::V6 from a sixteen element byte array.

Examples

use std::net::{IpAddr, Ipv6Addr};

let addr = IpAddr::from([
    25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8,
    17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8,
]);
assert_eq!(
    IpAddr::V6(Ipv6Addr::new(
        0x1918, 0x1716,
        0x1514, 0x1312,
        0x1110, 0x0f0e,
        0x0d0c, 0x0b0a
    )),
    addr
);

impl From<String> for OsString[src]

fn from(s: String) -> OsString[src]

Converts a String into a [OsString].

The conversion copies the data, and includes an allocation on the heap.

impl From<String> for Box<dyn Error + 'static + Sync + Send>[src]

fn from(err: String) -> Box<dyn Error + 'static + Sync + Send>[src]

Converts a String into a box of dyn [Error] + Send + Sync.

Examples

use std::error::Error;
use std::mem;

let a_string_error = "a string error".to_string();
let a_boxed_error = Box::<Error + Send + Sync>::from(a_string_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

impl<'a> From<CString> for Cow<'a, CStr>[src]

impl From<Box<CStr>> for CString[src]

fn from(s: Box<CStr>) -> CString[src]

Converts a Box<CStr> into a CString without copying or allocating.

impl From<String> for PathBuf[src]

fn from(s: String) -> PathBuf[src]

Converts a String into a PathBuf

This conversion does not allocate or copy memory.

impl From<CString> for Vec<u8>[src]

fn from(s: CString) -> Vec<u8>[src]

Converts a CString into a Vec<u8>.

The conversion consumes the CString, and removes the terminating NUL byte.

impl<'a> From<&'a Path> for Cow<'a, Path>[src]

impl From<DefaultEnvKey> for OsString[src]

impl From<OsString> for Arc<OsStr>[src]

fn from(s: OsString) -> Arc<OsStr>[src]

Converts a OsString into a Arc<OsStr> without copying or allocating.

impl From<CString> for Rc<CStr>[src]

fn from(s: CString) -> Rc<CStr>[src]

Converts a CString into a Rc<CStr> without copying or allocating.

impl<'_> From<&'_ OsStr> for Arc<OsStr>[src]

impl From<PathBuf> for Arc<Path>[src]

fn from(s: PathBuf) -> Arc<Path>[src]

Converts a Path into a Rc by copying the Path data into a new Rc buffer.

impl From<OsString> for PathBuf[src]

fn from(s: OsString) -> PathBuf[src]

Converts a OsString into a PathBuf

This conversion does not allocate or copy memory.

impl From<Ipv6Addr> for IpAddr[src]

impl From<RecvError> for TryRecvError[src]

impl From<ChildStderr> for Stdio[src]

fn from(child: ChildStderr) -> Stdio[src]

Converts a ChildStderr into a Stdio

Examples

use std::process::{Command, Stdio};

let reverse = Command::new("rev")
    .arg("non_existing_file.txt")
    .stderr(Stdio::piped())
    .spawn()
    .expect("failed reverse command");

let cat = Command::new("cat")
    .arg("-")
    .stdin(reverse.stderr.unwrap()) // Converted into a Stdio here
    .output()
    .expect("failed echo command");

assert_eq!(
    String::from_utf8_lossy(&cat.stdout),
    "rev: cannot open non_existing_file.txt: No such file or directory\n"
);

impl From<String> for Box<dyn Error + 'static>[src]

fn from(str_err: String) -> Box<dyn Error + 'static>[src]

Converts a String into a box of dyn [Error].

Examples

use std::error::Error;
use std::mem;

let a_string_error = "a string error".to_string();
let a_boxed_error = Box::<Error>::from(a_string_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))

impl From<PathBuf> for OsString[src]

fn from(path_buf: PathBuf) -> OsString[src]

Converts a PathBuf into a OsString

This conversion does not allocate or copy memory.

impl<T> From<PoisonError<T>> for TryLockError<T>[src]

impl From<[u16; 8]> for Ipv6Addr[src]

impl From<[u8; 16]> for Ipv6Addr[src]

impl<'_> From<&'_ Path> for Box<Path>[src]

impl<'_> From<&'_ OsStr> for Box<OsStr>[src]

impl From<CString> for Arc<CStr>[src]

fn from(s: CString) -> Arc<CStr>[src]

Converts a CString into a Arc<CStr> without copying or allocating.

impl From<Ipv6Addr> for u128[src]

fn from(ip: Ipv6Addr) -> u128[src]

Convert an Ipv6Addr into a host byte order u128.

Examples

use std::net::Ipv6Addr;

let addr = Ipv6Addr::new(
    0x1020, 0x3040, 0x5060, 0x7080,
    0x90A0, 0xB0C0, 0xD0E0, 0xF00D,
);
assert_eq!(0x102030405060708090A0B0C0D0E0F00D_u128, u128::from(addr));

impl<'_> From<&'_ Path> for Rc<Path>[src]

fn from(s: &Path) -> Rc<Path>[src]

Converts a Path into a Rc by copying the Path data into a new Rc buffer.

impl From<Ipv4Addr> for IpAddr[src]

impl<'a> From<&'a PathBuf> for Cow<'a, Path>[src]

impl<'_> From<&'_ OsStr> for Rc<OsStr>[src]

impl<'_> From<&'_ CStr> for Box<CStr>[src]

impl<'_, T> From<&'_ T> for PathBuf where
    T: AsRef<OsStr> + ?Sized
[src]

impl From<u32> for Ipv4Addr[src]

fn from(ip: u32) -> Ipv4Addr[src]

Converts a host byte order u32 into an Ipv4Addr.

Examples

use std::net::Ipv4Addr;

let addr = Ipv4Addr::from(0x0d0c0b0au32);
assert_eq!(Ipv4Addr::new(13, 12, 11, 10), addr);

impl From<ChildStdin> for Stdio[src]

fn from(child: ChildStdin) -> Stdio[src]

Converts a ChildStdin into a Stdio

Examples

ChildStdin will be converted to Stdio using Stdio::from under the hood.

use std::process::{Command, Stdio};

let reverse = Command::new("rev")
    .stdin(Stdio::piped())
    .spawn()
    .expect("failed reverse command");

let _echo = Command::new("echo")
    .arg("Hello, world!")
    .stdout(reverse.stdin.unwrap()) // Converted into a Stdio here
    .output()
    .expect("failed echo command");

// "!dlrow ,olleH" echoed to console

impl From<Box<OsStr>> for OsString[src]

fn from(boxed: Box<OsStr>) -> OsString[src]

Converts a Box<OsStr> into a OsString without copying or allocating.

impl<'_> From<&'_ Path> for Arc<Path>[src]

fn from(s: &Path) -> Arc<Path>[src]

Converts a Path into a Rc by copying the Path data into a new Rc buffer.

impl<'a> From<Cow<'a, OsStr>> for OsString[src]

impl<'_> From<&'_ CStr> for Rc<CStr>[src]

impl<'a> From<Cow<'a, CStr>> for CString[src]

impl From<NulError> for Error[src]

fn from(NulError) -> Error[src]

Converts a NulError into a io::Error.

impl<'a> From<OsString> for Cow<'a, OsStr>[src]

impl From<CString> for Box<CStr>[src]

fn from(s: CString) -> Box<CStr>[src]

Converts a CString into a Box<CStr> without copying or allocating.

impl From<OsString> for Rc<OsStr>[src]

fn from(s: OsString) -> Rc<OsStr>[src]

Converts a OsString into a Rc<OsStr> without copying or allocating.

impl From<SocketAddrV4> for SocketAddr[src]

fn from(sock4: SocketAddrV4) -> SocketAddr[src]

Converts a [SocketAddrV4] into a [SocketAddr::V4].

impl<'_> From<&'_ str> for Box<dyn Error + 'static>[src]

fn from(err: &str) -> Box<dyn Error + 'static>[src]

Converts a str into a box of dyn [Error].

Examples

use std::error::Error;
use std::mem;

let a_str_error = "a str error";
let a_boxed_error = Box::<Error>::from(a_str_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))

impl<'a> From<&'a OsString> for Cow<'a, OsStr>[src]

impl<'_, T> From<&'_ T> for OsString where
    T: AsRef<OsStr> + ?Sized
[src]

impl<'a> From<Cow<'a, Path>> for PathBuf[src]

impl<'a, E> From<E> for Box<dyn Error + 'a> where
    E: 'a + Error
[src]

fn from(err: E) -> Box<dyn Error + 'a>[src]

Converts a type of [Error] into a box of dyn [Error].

Examples

use std::error::Error;
use std::fmt;
use std::mem;

#[derive(Debug)]
struct AnError;

impl fmt::Display for AnError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f , "An error")
    }
}

impl Error for AnError {
    fn description(&self) -> &str {
        "Description of an error"
    }
}

let an_error = AnError;
assert!(0 == mem::size_of_val(&an_error));
let a_boxed_error = Box::<Error>::from(an_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))

impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + 'a + Sync + Send>[src]

fn from(err: Cow<'b, str>) -> Box<dyn Error + 'a + Sync + Send>[src]

Converts a [Cow] into a box of dyn [Error] + Send + Sync.

Examples

use std::error::Error;
use std::mem;
use std::borrow::Cow;

let a_cow_str_error = Cow::from("a str error");
let a_boxed_error = Box::<Error + Send + Sync>::from(a_cow_str_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

impl From<Ipv4Addr> for u32[src]

fn from(ip: Ipv4Addr) -> u32[src]

Converts an Ipv4Addr into a host byte order u32.

Examples

use std::net::Ipv4Addr;

let addr = Ipv4Addr::new(13, 12, 11, 10);
assert_eq!(0x0d0c0b0au32, u32::from(addr));

impl<'_> From<&'_ CStr> for CString[src]

impl<'a> From<PathBuf> for Cow<'a, Path>[src]

impl From<NonZeroI16> for i16[src]

impl From<u16> for i128[src]

Converts u16 to i128 losslessly.

impl From<u32> for i128[src]

Converts u32 to i128 losslessly.

impl From<isize> for AtomicIsize[src]

fn from(v: isize) -> AtomicIsize[src]

Converts an isize into an AtomicIsize.

impl From<i8> for isize[src]

Converts i8 to isize losslessly.

impl From<u8> for AtomicU8[src]

fn from(v: u8) -> AtomicU8[src]

Converts an u8 into an AtomicU8.

impl From<u8> for u64[src]

Converts u8 to u64 losslessly.

impl From<u16> for u64[src]

Converts u16 to u64 losslessly.

impl From<NonZeroI32> for i32[src]

impl From<i64> for AtomicI64[src]

fn from(v: i64) -> AtomicI64[src]

Converts an i64 into an AtomicI64.

impl From<NonZeroU64> for u64[src]

impl From<NonZeroI8> for i8[src]

impl From<u8> for char[src]

Maps a byte in 0x00...0xFF to a char whose code point has the same value, in U+0000 to U+00FF.

Unicode is designed such that this effectively decodes bytes with the character encoding that IANA calls ISO-8859-1. This encoding is compatible with ASCII.

Note that this is different from ISO/IEC 8859-1 a.k.a. ISO 8859-1 (with one less hyphen), which leaves some "blanks", byte values that are not assigned to any character. ISO-8859-1 (the IANA one) assigns them to the C0 and C1 control codes.

Note that this is also different from Windows-1252 a.k.a. code page 1252, which is a superset ISO/IEC 8859-1 that assigns some (not all!) blanks to punctuation and various Latin characters.

To confuse things further, on the Web ascii, iso-8859-1, and windows-1252 are all aliases for a superset of Windows-1252 that fills the remaining blanks with corresponding C0 and C1 control codes.

fn from(i: u8) -> char[src]

Converts a u8 into a char.

Examples

use std::mem;

fn main() {
    let u = 32 as u8;
    let c = char::from(u);
    assert!(4 == mem::size_of_val(&c))
}

impl From<u64> for AtomicU64[src]

fn from(v: u64) -> AtomicU64[src]

Converts an u64 into an AtomicU64.

impl From<NonZeroU32> for u32[src]

impl From<char> for u32[src]

fn from(c: char) -> u32[src]

Converts a char into a u32.

Examples

use std::mem;

fn main() {
    let c = 'c';
    let u = u32::from(c);
    assert!(4 == mem::size_of_val(&u))
}

impl From<usize> for AtomicUsize[src]

fn from(v: usize) -> AtomicUsize[src]

Converts an usize into an AtomicUsize.

impl From<u16> for usize[src]

Converts u16 to usize losslessly.

impl From<u32> for i64[src]

Converts u32 to i64 losslessly.

impl From<bool> for i64[src]

Converts a bool to a i64. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(i64::from(true), 1);
assert_eq!(i64::from(false), 0);

impl From<NonZeroUsize> for usize[src]

impl<T> From<T> for UnsafeCell<T>[src]

impl From<u8> for isize[src]

Converts u8 to isize losslessly.

impl From<i16> for i128[src]

Converts i16 to i128 losslessly.

impl From<u16> for AtomicU16[src]

fn from(v: u16) -> AtomicU16[src]

Converts an u16 into an AtomicU16.

impl From<i32> for AtomicI32[src]

fn from(v: i32) -> AtomicI32[src]

Converts an i32 into an AtomicI32.

impl From<u16> for f32[src]

Converts u16 to f32 losslessly.

impl From<NonZeroU8> for u8[src]

impl From<i8> for i64[src]

Converts i8 to i64 losslessly.

impl From<bool> for u64[src]

Converts a bool to a u64. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(u64::from(true), 1);
assert_eq!(u64::from(false), 0);

impl From<bool> for isize[src]

Converts a bool to a isize. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(isize::from(true), 1);
assert_eq!(isize::from(false), 0);

impl From<i32> for i128[src]

Converts i32 to i128 losslessly.

impl From<bool> for u16[src]

Converts a bool to a u16. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(u16::from(true), 1);
assert_eq!(u16::from(false), 0);

impl From<bool> for AtomicBool[src]

fn from(b: bool) -> AtomicBool[src]

Converts a bool into an AtomicBool.

Examples

use std::sync::atomic::AtomicBool;
let atomic_bool = AtomicBool::from(true);
assert_eq!(format!("{:?}", atomic_bool), "true")

impl From<u16> for u128[src]

Converts u16 to u128 losslessly.

impl From<i16> for f32[src]

Converts i16 to f32 losslessly.

impl From<NonZeroIsize> for isize[src]

impl<'_, T> From<&'_ T> for NonNull<T> where
    T: ?Sized
[src]

impl From<i32> for i64[src]

Converts i32 to i64 losslessly.

impl From<u64> for i128[src]

Converts u64 to i128 losslessly.

impl From<i16> for i32[src]

Converts i16 to i32 losslessly.

impl From<u8> for u16[src]

Converts u8 to u16 losslessly.

impl From<u8> for usize[src]

Converts u8 to usize losslessly.

impl From<bool> for i32[src]

Converts a bool to a i32. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(i32::from(true), 1);
assert_eq!(i32::from(false), 0);

impl From<u16> for u32[src]

Converts u16 to u32 losslessly.

impl From<u32> for u128[src]

Converts u32 to u128 losslessly.

impl From<i8> for i16[src]

Converts i8 to i16 losslessly.

impl From<u8> for u32[src]

Converts u8 to u32 losslessly.

impl<T> From<Unique<T>> for NonNull<T> where
    T: ?Sized
[src]

impl From<u32> for f64[src]

Converts u32 to f64 losslessly.

impl From<i16> for i64[src]

Converts i16 to i64 losslessly.

impl From<bool> for i16[src]

Converts a bool to a i16. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(i16::from(true), 1);
assert_eq!(i16::from(false), 0);

impl From<bool> for usize[src]

Converts a bool to a usize. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(usize::from(true), 1);
assert_eq!(usize::from(false), 0);

impl From<i8> for AtomicI8[src]

fn from(v: i8) -> AtomicI8[src]

Converts an i8 into an AtomicI8.

impl From<u8> for f64[src]

Converts u8 to f64 losslessly.

impl<T> From<T> for RefCell<T>[src]

impl<T> From<T> for Cell<T>[src]

impl From<u32> for AtomicU32[src]

fn from(v: u32) -> AtomicU32[src]

Converts an u32 into an AtomicU32.

impl From<u8> for f32[src]

Converts u8 to f32 losslessly.

impl<T> From<*mut T> for AtomicPtr<T>[src]

impl From<NonZeroU16> for u16[src]

impl From<i16> for AtomicI16[src]

fn from(v: i16) -> AtomicI16[src]

Converts an i16 into an AtomicI16.

impl From<bool> for i128[src]

Converts a bool to a i128. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(i128::from(true), 1);
assert_eq!(i128::from(false), 0);

impl From<i16> for f64[src]

Converts i16 to f64 losslessly.

impl From<!> for TryFromIntError[src]

impl From<NonZeroI128> for i128[src]

impl<'a, T> From<&'a Option<T>> for Option<&'a T>[src]

impl From<u8> for i16[src]

Converts u8 to i16 losslessly.

impl From<u8> for i64[src]

Converts u8 to i64 losslessly.

impl<T> From<T> for Poll<T>[src]

impl From<u16> for i32[src]

Converts u16 to i32 losslessly.

impl From<u64> for u128[src]

Converts u64 to u128 losslessly.

impl From<u8> for i128[src]

Converts u8 to i128 losslessly.

impl<T> From<T> for Option<T>[src]

impl From<i8> for f64[src]

Converts i8 to f64 losslessly.

impl From<bool> for u8[src]

Converts a bool to a u8. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(u8::from(true), 1);
assert_eq!(u8::from(false), 0);

impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T>[src]

impl From<bool> for u128[src]

Converts a bool to a u128. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(u128::from(true), 1);
assert_eq!(u128::from(false), 0);

impl From<i8> for i128[src]

Converts i8 to i128 losslessly.

impl From<!> for Infallible[src]

impl From<u8> for u128[src]

Converts u8 to u128 losslessly.

impl From<NonZeroI64> for i64[src]

impl From<u16> for f64[src]

Converts u16 to f64 losslessly.

impl From<i8> for f32[src]

Converts i8 to f32 losslessly.

impl From<bool> for i8[src]

Converts a bool to a i8. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(i8::from(true), 1);
assert_eq!(i8::from(false), 0);

impl From<u8> for i32[src]

Converts u8 to i32 losslessly.

impl<'_, T> From<&'_ mut T> for NonNull<T> where
    T: ?Sized
[src]

impl From<u16> for i64[src]

Converts u16 to i64 losslessly.

impl From<NonZeroU128> for u128[src]

impl From<bool> for u32[src]

Converts a bool to a u32. The resulting value is 0 for false and 1 for true values.

Examples

assert_eq!(u32::from(true), 1);
assert_eq!(u32::from(false), 0);

impl From<i64> for i128[src]

Converts i64 to i128 losslessly.

impl From<Infallible> for TryFromSliceError[src]

impl From<i8> for i32[src]

Converts i8 to i32 losslessly.

impl From<i16> for isize[src]

Converts i16 to isize losslessly.

impl From<f32> for f64[src]

Converts f32 to f64 losslessly.

impl From<u32> for u64[src]

Converts u32 to u64 losslessly.

impl From<Infallible> for TryFromIntError[src]

impl From<i32> for f64[src]

Converts i32 to f64 losslessly.

impl<'_> From<&'_ str> for Box<str>[src]

fn from(s: &str) -> Box<str>[src]

Converts a &str into a Box<str>

This conversion allocates on the heap and performs a copy of s.

Examples

let boxed: Box<str> = Box::from("hello");
println!("{}", boxed);

impl From<String> for Rc<str>[src]

impl<T> From<Vec<T>> for Arc<[T]>[src]

impl<'_> From<&'_ str> for Arc<str>[src]

impl<'_> From<&'_ str> for Rc<str>[src]

impl<T> From<Box<T>> for Rc<T> where
    T: ?Sized
[src]

impl<'_> From<&'_ str> for String[src]

impl<'_, T> From<&'_ [T]> for Vec<T> where
    T: Clone
[src]

impl<'_, T> From<&'_ [T]> for Box<[T]> where
    T: Copy
[src]

fn from(slice: &[T]) -> Box<[T]>[src]

Converts a &[T] into a Box<[T]>

This conversion allocates on the heap and performs a copy of slice.

Examples

// create a &[u8] which will be used to create a Box<[u8]>
let slice: &[u8] = &[104, 101, 108, 108, 111];
let boxed_slice: Box<[u8]> = Box::from(slice);

println!("{:?}", boxed_slice);

impl From<String> for Vec<u8>[src]

fn from(string: String) -> Vec<u8>[src]

Converts the given String to a vector Vec that holds values of type u8.

Examples

Basic usage:

let s1 = String::from("hello world");
let v1 = Vec::from(s1);

for b in v1 {
    println!("{}", b);
}

impl<'a> From<String> for Cow<'a, str>[src]

impl<'a, T> From<Vec<T>> for Cow<'a, [T]> where
    T: Clone
[src]

impl From<String> for Arc<str>[src]

impl<'_, T> From<&'_ [T]> for Arc<[T]> where
    T: Clone
[src]

impl<T> From<Box<[T]>> for Vec<T>[src]

impl<'_, T> From<&'_ mut [T]> for Vec<T> where
    T: Clone
[src]

impl<T> From<T> for Rc<T>[src]

impl From<Box<str>> for Box<[u8]>[src]

fn from(s: Box<str>) -> Box<[u8]>[src]

Converts a Box<str>> into a Box<[u8]>

This conversion does not allocate on the heap and happens in place.

Examples

// create a Box<str> which will be used to create a Box<[u8]>
let boxed: Box<str> = Box::from("hello");
let boxed_str: Box<[u8]> = Box::from(boxed);

// create a &[u8] which will be used to create a Box<[u8]>
let slice: &[u8] = &[104, 101, 108, 108, 111];
let boxed_slice = Box::from(slice);

assert_eq!(boxed_slice, boxed_str);

impl<T> From<BinaryHeap<T>> for Vec<T>[src]

impl From<Box<str>> for String[src]

fn from(s: Box<str>) -> String[src]

Converts the given boxed str slice to a String. It is notable that the str slice is owned.

Examples

Basic usage:

let s1: String = String::from("hello world");
let s2: Box<str> = s1.into_boxed_str();
let s3: String = String::from(s2);

assert_eq!("hello world", s3)

impl From<AllocErr> for CollectionAllocErr[src]

impl<T> From<Vec<T>> for Box<[T]>[src]

impl<T> From<Box<T>> for Pin<Box<T>> where
    T: ?Sized
[src]

fn from(boxed: Box<T>) -> Pin<Box<T>>[src]

Converts a Box<T> into a Pin<Box<T>>

This conversion does not allocate on the heap and happens in place.

impl<'a> From<&'a String> for Cow<'a, str>[src]

impl<T> From<Vec<T>> for VecDeque<T>[src]

impl<'_> From<&'_ str> for Vec<u8>[src]

impl<T> From<VecDeque<T>> for Vec<T>[src]

impl<'a> From<Cow<'a, str>> for String[src]

impl<T> From<T> for Arc<T>[src]

impl<T> From<T> for Box<T>[src]

fn from(t: T) -> Box<T>[src]

Converts a generic type T into a Box<T>

The conversion allocates on the heap and moves t from the stack into it.

Examples

let x = 5;
let boxed = Box::new(5);

assert_eq!(Box::from(x), boxed);

impl<'a> From<&'a str> for Cow<'a, str>[src]

impl<T> From<Box<T>> for Arc<T> where
    T: ?Sized
[src]

impl From<String> for Box<str>[src]

fn from(s: String) -> Box<str>[src]

Converts the given String to a boxed str slice that is owned.

Examples

Basic usage:

let s1: String = String::from("hello world");
let s2: Box<str> = Box::from(s1);
let s3: String = String::from(s2);

assert_eq!("hello world", s3)

impl<'a, T> From<Cow<'a, [T]>> for Vec<T> where
    [T]: ToOwned,
    <[T] as ToOwned>::Owned == Vec<T>, 
[src]

impl From<LayoutErr> for CollectionAllocErr[src]

impl<'a, T> From<&'a Vec<T>> for Cow<'a, [T]> where
    T: Clone
[src]

impl<T> From<Vec<T>> for BinaryHeap<T> where
    T: Ord
[src]

impl<'_, T> From<&'_ [T]> for Rc<[T]> where
    T: Clone
[src]

impl<T> From<Vec<T>> for Rc<[T]>[src]

impl<'a, T> From<&'a [T]> for Cow<'a, [T]> where
    T: Clone
[src]

impl From<Vec<u8>> for BytesMut[src]

impl From<Vec<u8>> for Bytes[src]

impl<'a> From<&'a [u8]> for Bytes[src]

impl<'a> From<&'a str> for Bytes[src]

impl<'a> From<&'a str> for BytesMut[src]

impl From<String> for Bytes[src]

impl<'a> From<&'a [u8]> for BytesMut[src]

impl From<BytesMut> for Bytes[src]

impl From<Bytes> for BytesMut[src]

impl From<String> for BytesMut[src]

impl<T> From<T> for ShardedLock<T>

impl<T> From<T> for CachePadded<T>

impl<'a, D> From<PoisonError<MutexGuard<'a, D>>> for MutexDrainError<D> where
    D: Drain
[src]

impl From<Error> for Error[src]

impl<T> From<OwnedKV<T>> for OwnedKVList where
    T: SendSyncRefUnwindSafeKV + 'static, 
[src]

impl From<Error> for Error[src]

impl From<Error> for Error[src]

impl<V> From<(&'static str, V)> for SingleKV<V> where
    V: Value
[src]

impl<T> From<TryLockError<T>> for AsyncError[src]

impl<T> From<PoisonError<T>> for AsyncError[src]

impl<T> From<TrySendError<T>> for AsyncError[src]

impl<T> From<SendError<T>> for AsyncError[src]

impl<'a> From<&'a Uuid> for SimpleRef<'a>[src]

impl From<BytesError> for Error[src]

impl From<Uuid> for Urn[src]

impl<'a> From<&'a Uuid> for HyphenatedRef<'a>[src]

impl<'a> From<&'a Uuid> for UrnRef<'a>[src]

impl From<Uuid> for Simple[src]

impl From<ParseError> for Error[src]

impl From<Uuid> for Hyphenated[src]

impl From<Vec<usize>> for IndexVec[src]

impl<X> From<RangeInclusive<X>> for Uniform<X> where
    X: SampleUniform
[src]

impl From<Vec<u32>> for IndexVec[src]

impl<X> From<Range<X>> for Uniform<X> where
    X: SampleUniform
[src]

impl From<TimerError> for Error[src]

impl From<Error> for Error[src]

impl From<ChaChaCore> for ChaChaRng[src]

impl<A, T, S> From<A> for Cache<A, T> where
    A: Deref<Target = ArcSwapAny<T, S>>,
    S: LockStorage,
    T: RefCnt
[src]

impl<T, S> From<T> for ArcSwapAny<T, S> where
    S: LockStorage,
    T: RefCnt
[src]

impl<T> From<&'static T> for NotifyHandle where
    T: Notify
[src]

impl<T, E> From<Result<T, E>> for FutureResult<T, E>[src]

impl<T> From<Arc<T>> for NotifyHandle where
    T: Notify + 'static, 
[src]

impl<'a, T> From<NodeToHandle<'a, T>> for NotifyHandle[src]

impl<T> From<T> for Async<T>[src]

impl From<()> for ConnectionError[src]

impl From<u32> for StreamId[src]

impl From<WriteError> for Error[src]

impl From<FramingError> for ConnectionError[src]

impl From<StreamId> for usize[src]

impl From<StreamId> for u32[src]

impl From<UnixReady> for Ready[src]

impl From<ReadinessState> for usize[src]

impl From<Token> for usize[src]

impl From<Ready> for UnixReady[src]

impl From<usize> for Token[src]

impl<T> From<EnterError> for BlockError<T>[src]

impl<'a, U> From<Notify<'a, U>> for NotifyHandle where
    U: Unpark
[src]

impl From<EnterError> for RunTimeoutError[src]

impl From<OpenOptions> for OpenOptions[src]

impl From<State> for usize[src]

impl From<State> for usize[src]

impl From<State> for usize[src]

impl From<State> for usize[src]

impl From<State> for usize[src]

impl From<Lifecycle> for usize[src]

impl From<BlockingState> for usize[src]

impl From<Lifecycle> for usize[src]

impl From<State> for usize[src]

impl From<State> for usize[src]

impl<'g, T> From<Shared<'g, T>> for Atomic<T>

fn from(ptr: Shared<'g, T>) -> Atomic<T>

Returns a new atomic pointer pointing to ptr.

Examples

use crossbeam_epoch::{Atomic, Shared};

let a = Atomic::<i32>::from(Shared::<i32>::null());

impl<T> From<Box<T>> for Owned<T>

fn from(b: Box<T>) -> Owned<T>

Returns a new owned pointer pointing to b.

Panics

Panics if the pointer (the Box) is not properly aligned.

Examples

use crossbeam_epoch::Owned;

let o = unsafe { Owned::from_raw(Box::into_raw(Box::new(1234))) };

impl<T> From<Box<T>> for Atomic<T>

impl<'g, T> From<*const T> for Shared<'g, T>

fn from(raw: *const T) -> Shared<'g, T>

Returns a new pointer pointing to raw.

Panics

Panics if raw is not properly aligned.

Examples

use crossbeam_epoch::Shared;

let p = unsafe { Shared::from(Box::into_raw(Box::new(1234)) as *const _) };
assert!(!p.is_null());

impl<T> From<*const T> for Atomic<T>

fn from(raw: *const T) -> Atomic<T>

Returns a new atomic pointer pointing to raw.

Examples

use std::ptr;
use crossbeam_epoch::Atomic;

let a = Atomic::<i32>::from(ptr::null::<i32>());

impl<T> From<T> for Atomic<T>

impl<T> From<Owned<T>> for Atomic<T>

fn from(owned: Owned<T>) -> Atomic<T>

Returns a new atomic pointer pointing to owned.

Examples

use crossbeam_epoch::{Atomic, Owned};

let a = Atomic::<i32>::from(Owned::new(1234));

impl<T> From<T> for Owned<T>

impl<A> From<A> for ArrayVec<A> where
    A: Array
[src]

Create an ArrayVec from an array.

use arrayvec::ArrayVec;

let mut array = ArrayVec::from([1, 2, 3]);
assert_eq!(array.len(), 3);
assert_eq!(array.capacity(), 3);

impl<R, G, T> From<T> for ReentrantMutex<R, G, T> where
    G: GetThreadId,
    R: RawMutex, 

impl<R, T> From<T> for RwLock<R, T> where
    R: RawRwLock, 

impl<R, T> From<T> for Mutex<R, T> where
    R: RawMutex, 

impl<O, T> From<O> for OwningRef<O, T> where
    O: StableDeref<Target = T> + Deref,
    T: ?Sized

impl<O, T> From<OwningRefMut<O, T>> for OwningRef<O, T> where
    O: StableDeref<Target = T> + DerefMut,
    T: ?Sized

impl<O, T> From<O> for OwningRefMut<O, T> where
    O: StableDeref<Target = T> + DerefMut,
    T: ?Sized

impl<A> From<A> for SmallVec<A> where
    A: Array, 

impl<'a, A> From<&'a [<A as Array>::Item]> for SmallVec<A> where
    A: Array,
    <A as Array>::Item: Clone

impl<A> From<Vec<<A as Array>::Item>> for SmallVec<A> where
    A: Array, 

impl<T> From<T> for Lock<T>[src]

impl<T> From<(T, TrySendError)> for TrySendError<T>[src]

impl<T> From<(T, TrySendError)> for UnboundedTrySendError<T>[src]

impl<S> From<S> for Dispatch where
    S: Subscriber + Send + Sync + 'static, 
[src]

impl From<RecvError> for RecvTimeoutError[src]

impl<T> From<SendError<T>> for SendTimeoutError<T>[src]

impl<T> From<SendError<T>> for TrySendError<T>[src]

impl From<RecvError> for TryRecvError[src]

impl<T, S> From<(T, S)> for Box<dyn Serialisable> where
    T: Send + Debug + 'static,
    S: Serialiser<T> + 'static, 
[src]

impl<T> From<T> for Box<dyn Serialisable> where
    T: Send + Debug + Serialisable + Sized + 'static, 
[src]

Loading content...

Implementors

impl From<(SystemPath, Uuid)> for ActorPath[src]

impl From<u8> for SerIdents[src]

impl From<TransportParseError> for PathParseError[src]

impl From<Error> for NetworkError[src]

impl From<AddrParseError> for PathParseError[src]

impl<'a> From<&'a IpAddr> for AddressType[src]

impl<T> From<T> for T[src]

Loading content...