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

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 an implementation of Into thanks to the blanket implementation in the standard library.

Only implement Into when targeting a version prior to Rust 1.41 and converting to a type outside the current crate. From was not able to do these types of conversions in earlier versions 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. The From trait is intended for perfect conversions. If the conversion can fail or is not perfect, 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

Converts to this type from the input type.

Implementations on Foreign Types

Converts a Cow<'a, OsStr> into a Box<OsStr>, by copying the contents if they are borrowed.

Converts a &CStr into a Rc<CStr>, by copying the contents into a newly allocated Rc.

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

Construct an ExitCode from an arbitrary u8 value.

Converts a PathBuf into an OsString

This conversion does not allocate or copy memory.

Copies any value implementing AsRef<OsStr> into a newly allocated OsString.

Copies the string into a newly allocated Box<OsStr>.

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::<dyn Error>::from(a_string_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))

Converts a Cow<'a, CStr> into a Box<CStr>, by copying the contents if they are borrowed.

Creates a boxed Path from a reference.

This will allocate and clone path to it.

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.

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

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));

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

Converts a Cow<'a, CStr> into a CString, by copying the contents if they are borrowed.

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::<dyn Error>::from(a_cow_str_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))

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::<dyn Error + Send + Sync>::from(a_str_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

Create a new cell with its contents set to value.

Example
#![feature(once_cell)]

use std::lazy::SyncOnceCell;

let a = SyncOnceCell::from(3);
let b = SyncOnceCell::new();
b.set(3)?;
assert_eq!(a, b);
Ok(())

Converts a Cow<'a, OsStr> into an OsString, by copying the contents if they are borrowed.

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::<dyn Error + Send + Sync>::from(a_string_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

Converts an Ipv4Addr into a host byte order u32.

Examples
use std::net::Ipv4Addr;

let addr = Ipv4Addr::new(0x12, 0x34, 0x56, 0x78);
assert_eq!(0x12345678, u32::from(addr));

Converts a CString into a Vec<u8>.

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

Converts a String into an OsString.

This conversion does not allocate or copy memory.

Converts a CString into an Rc<CStr> by moving the CString data into a new Arc buffer.

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::<dyn Error + Send + Sync>::from(a_cow_str_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

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 {}

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

Converts a PathBuf into an Rc<Path> by moving the PathBuf data into a new Rc buffer.

Converts a &CStr into a Box<CStr>, by copying the contents into a newly allocated Box.

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::<dyn Error>::from(a_str_error);
assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))

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

Converts a Vec<NonZeroU8> into a CString without copying nor checking for inner null bytes.

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

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

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

Creates a boxed Path from a clone-on-write pointer.

Converting from a Cow::Owned does not clone or allocate.

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 {}

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::<dyn Error + Send + Sync>::from(an_error);
assert!(
    mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))

Converts an OsString into an Rc<OsStr> by moving the OsString data into a new Rc buffer.

Copies the contents of the &CStr into a newly allocated CString.

Copies the string into a newly allocated Rc<OsStr>.

Converts u16 to i32 losslessly.

Converts u16 to u32 losslessly.

Converts u16 to u128 losslessly.

Converts u8 to u32 losslessly.

Converts u32 to u128 losslessly.

Converts u8 to f32 losslessly.

Converts i32 to f64 losslessly.

Converts u32 to i64 losslessly.

Converts i16 to isize losslessly.

Converts u16 to usize losslessly.

Converts a NonZeroUsize into an usize

Converts i16 to f64 losslessly.

Converts a NonZeroU128 into an u128

Converts u32 to f64 losslessly.

Converts u8 to f64 losslessly.

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);

Converts u16 to i64 losslessly.

Converts u16 to f64 losslessly.

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);

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);

Converts a NonZeroU8 into an u8

Converts a NonZeroI128 into an i128

Converts u16 to u64 losslessly.

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);

Converts i8 to i128 losslessly.

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);

Converts i8 to f64 losslessly.

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);

Converts a NonZeroI8 into an i8

Converts u8 to u64 losslessly.

Converts a NonZeroI64 into an i64

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);

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);

Converts i8 to isize losslessly.

Converts a char into a u128.

Examples
use std::mem;

let c = '⚙';
let u = u128::from(c);
assert!(16 == mem::size_of_val(&u))

Converts u8 to u16 losslessly.

Maps a byte in 0x00..=0xFF to a char whose code point has the same value, in U+0000..=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.

Converts a u8 into a char.

Examples
use std::mem;

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

Converts u8 to isize losslessly.

Converts u8 to i128 losslessly.

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);

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);

Converts u8 to usize losslessly.

Converts i8 to i32 losslessly.

Converts a NonZeroIsize into an isize

Converts u64 to i128 losslessly.

Converts i16 to i128 losslessly.

Converts u8 to i64 losslessly.

Converts i8 to f32 losslessly.

Converts i64 to i128 losslessly.

Converts u8 to u128 losslessly.

Converts u16 to i128 losslessly.

Converts i32 to i64 losslessly.

Converts u32 to i128 losslessly.

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);

Converts u8 to i32 losslessly.

Converts i8 to i64 losslessly.

Converts i16 to i64 losslessly.

Converts i8 to i16 losslessly.

Converts a NonZeroU64 into an u64

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);

Converts a &T to a NonNull<T>.

This conversion is safe and infallible since references cannot be null.

Converts u32 to u64 losslessly.

Converts a NonZeroU16 into an u16

Converts a NonZeroI32 into an i32

Converts u16 to f32 losslessly.

Converts a &mut T to a NonNull<T>.

This conversion is safe and infallible since references cannot be null.

Converts a NonZeroU32 into an u32

Converts u64 to u128 losslessly.

Converts f32 to f64 losslessly.

Converts a char into a u64.

Examples
use std::mem;

let c = '👤';
let u = u64::from(c);
assert!(8 == mem::size_of_val(&u))

Converts a NonZeroI16 into an i16

Converts i32 to i128 losslessly.

Converts a char into a u32.

Examples
use std::mem;

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

Converts i16 to i32 losslessly.

Converts u8 to i16 losslessly.

Converts i16 to f32 losslessly.

Convert a clone-on-write slice into a vector.

If s already owns a Vec<T>, it will be returned directly. If s is borrowing a slice, a new Vec<T> will be allocated and filled by cloning s’s items into it.

Examples
let o: Cow<[i32]> = Cow::Owned(vec![1, 2, 3]);
let b: Cow<[i32]> = Cow::Borrowed(&[1, 2, 3]);
assert_eq!(Vec::from(o), Vec::from(b));

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}");

Allocate a Vec<T> and fill it by cloning s’s items.

Examples
assert_eq!(Vec::from(&mut [1, 2, 3][..]), vec![1, 2, 3]);

Converts a 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);

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}");
}

Convert a vector into a boxed slice.

If v has excess capacity, its items will be moved into a newly-allocated buffer with exactly the right capacity.

Examples
assert_eq!(Box::from(vec![1, 2, 3]), vec![1, 2, 3].into_boxed_slice());

Allocate a Vec<u8> and fill it with a UTF-8 string.

Examples
assert_eq!(Vec::from("123"), vec![b'1', b'2', b'3']);

Create a reference-counted pointer from a clone-on-write pointer by copying its content.

Example
let cow: Cow<str> = Cow::Borrowed("eggplant");
let shared: Rc<str> = Rc::from(cow);
assert_eq!("eggplant", &shared[..]);

Converts a clone-on-write string to an owned instance of String.

This extracts the owned string, clones the string if it is not already owned.

Example
// If the string is not owned...
let cow: Cow<str> = Cow::Borrowed("eggplant");
// It will allocate on the heap and copy the string.
let owned: String = String::from(cow);
assert_eq!(&owned[..], "eggplant");

Convert a boxed slice into a vector by transferring ownership of the existing heap allocation.

Examples
let b: Box<[i32]> = vec![1, 2, 3].into_boxed_slice();
assert_eq!(Vec::from(b), vec![1, 2, 3]);

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:?}");

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)

Converts a &String into a String.

This clones s and returns the clone.

Allocate a Vec<T> and fill it by cloning s’s items.

Examples
assert_eq!(Vec::from(&mut [1, 2, 3]), vec![1, 2, 3]);

Converts a Vec<T> into a BinaryHeap<T>.

This conversion happens in-place, and has O(n) time complexity.

Converts a &str into a String.

The result is allocated on the heap.

Converts a generic type T into an Rc<T>

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

Example
let x = 5;
let rc = Rc::new(5);

assert_eq!(Rc::from(x), rc);

Allocate a reference-counted string slice and copy v into it.

Example
let shared: Rc<str> = Rc::from("statue");
assert_eq!("statue", &shared[..]);

Allocate a Vec<T> and move s’s items into it.

Examples
assert_eq!(Vec::from([1, 2, 3]), vec![1, 2, 3]);

Allocate a Vec<T> and fill it by cloning s’s items.

Examples
assert_eq!(Vec::from(&[1, 2, 3][..]), vec![1, 2, 3]);

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)

Converts a Cow<'_, [T]> into a Box<[T]>

When cow is the Cow::Borrowed variant, this conversion allocates on the heap and copies the underlying slice. Otherwise, it will try to reuse the owned Vec’s allocation.

Converts a [T; N] into a Box<[T]>

This conversion moves the array to newly heap-allocated memory.

Examples
let boxed: Box<[u8]> = Box::from([4, 2]);
println!("{boxed:?}");

Allocate a reference-counted slice and move v’s items into it.

Example
let original: Box<Vec<i32>> = Box::new(vec![1, 2, 3]);
let shared: Rc<Vec<i32>> = Rc::from(original);
assert_eq!(vec![1, 2, 3], *shared);

Allocate a reference-counted string slice and copy v into it.

Example
let original: String = "statue".to_owned();
let shared: Rc<str> = Rc::from(original);
assert_eq!("statue", &shared[..]);

Converts a &mut str into a String.

The result is allocated on the heap.

Allocate a reference-counted slice and fill it by cloning v’s items.

Example
let original: &[i32] = &[1, 2, 3];
let shared: Rc<[i32]> = Rc::from(original);
assert_eq!(&[1, 2, 3], &shared[..]);

Move a boxed object to a new, reference counted, allocation.

Example
let original: Box<i32> = Box::new(1);
let shared: Rc<i32> = Rc::from(original);
assert_eq!(1, *shared);

Allocate a Vec<T> and fill it by cloning s’s items.

Examples
assert_eq!(Vec::from(b"raw"), vec![b'r', b'a', b'w']);

Turn a VecDeque<T> into a Vec<T>.

This never needs to re-allocate, but does need to do O(n) data movement if the circular buffer doesn’t happen to be at the beginning of the allocation.

Examples
use std::collections::VecDeque;

// This one is *O*(1).
let deque: VecDeque<_> = (1..5).collect();
let ptr = deque.as_slices().0.as_ptr();
let vec = Vec::from(deque);
assert_eq!(vec, [1, 2, 3, 4]);
assert_eq!(vec.as_ptr(), ptr);

// This one needs data rearranging.
let mut deque: VecDeque<_> = (1..5).collect();
deque.push_front(9);
deque.push_front(8);
let ptr = deque.as_slices().1.as_ptr();
let vec = Vec::from(deque);
assert_eq!(vec, [8, 9, 1, 2, 3, 4]);
assert_eq!(vec.as_ptr(), ptr);
use std::collections::BinaryHeap;

let mut h1 = BinaryHeap::from([1, 4, 2, 3]);
let mut h2: BinaryHeap<_> = [1, 4, 2, 3].into();
while let Some((a, b)) = h1.pop().zip(h2.pop()) {
    assert_eq!(a, b);
}

Converts a [T; N] into a LinkedList<T>.

use std::collections::LinkedList;

let list1 = LinkedList::from([1, 2, 3, 4]);
let list2: LinkedList<_> = [1, 2, 3, 4].into();
assert_eq!(list1, list2);

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);

Converts a Cow<'_, str> into a Box<str>

When cow is the Cow::Borrowed variant, this conversion allocates on the heap and copies the underlying str. Otherwise, it will try to reuse the owned String’s allocation.

Examples
use std::borrow::Cow;

let unboxed = Cow::Borrowed("hello");
let boxed: Box<str> = Box::from(unboxed);
println!("{boxed}");
let unboxed = Cow::Owned("hello".to_string());
let boxed: Box<str> = Box::from(unboxed);
println!("{boxed}");

Converts a BinaryHeap<T> into a Vec<T>.

This conversion requires no data movement or allocation, and has constant time complexity.

Allocates an owned String from a single character.

Example
let c: char = 'a';
let s: String = String::from(c);
assert_eq!("a", &s[..]);

Convert the Choice wrapper into a bool, depending on whether the underlying u8 was a 0 or a 1.

Note

This function exists to avoid having higher-level cryptographic protocol implementations duplicating this pattern.

The intended use case for this conversion is at the end of a higher-level primitive implementation: for example, in checking a keyed MAC, where the verification should happen in constant-time (and thus use a Choice) but it is safe to return a bool at the end of the verification.

You can turn a Colour into a Style with the foreground colour set with the From trait.

use ansi_term::{Style, Colour};
let green_foreground = Style::default().fg(Colour::Green);
assert_eq!(green_foreground, Colour::Green.normal());
assert_eq!(green_foreground, Colour::Green.into());
assert_eq!(green_foreground, Style::from(Colour::Green));

String converstion.

Create level by number

Calls AsRef::as_mut then uses the full slice as the initial length.

Example
let mut arr = [0, 0];
let mut sv = SliceVec::from(&mut arr);

The output has a length equal to the full array.

If you want to select a length, use from_array_len

Uses the full slice as the initial length.

Example
let mut arr = [0_i32; 2];
let mut sv = SliceVec::from(&mut arr[..]);

Notes

The underlying pipe is not set to non-blocking.

Notes

The underlying pipe is not set to non-blocking.

Notes

The underlying pipe is not set to non-blocking.

A Response can be piped as the Body of another request.

Convert a Uri from parts

Examples

Relative URI

let mut parts = Parts::default();
parts.path_and_query = Some("/foo".parse().unwrap());

let uri = Uri::from_parts(parts).unwrap();

assert_eq!(uri.path(), "/foo");

assert!(uri.scheme().is_none());
assert!(uri.authority().is_none());

Absolute URI

let mut parts = Parts::default();
parts.scheme = Some("http".parse().unwrap());
parts.authority = Some("foo.com".parse().unwrap());
parts.path_and_query = Some("/foo".parse().unwrap());

let uri = Uri::from_parts(parts).unwrap();

assert_eq!(uri.scheme().unwrap().as_str(), "http");
assert_eq!(uri.authority().unwrap(), "foo.com");
assert_eq!(uri.path(), "/foo");

On Windows, a corresponding From<&impl AsRawSocket> implementation exists.

The caller must ensure S is actually a socket.

Examples
use indexmap::IndexMap;

let map1 = IndexMap::from([(1, 2), (3, 4)]);
let map2: IndexMap<_, _> = [(1, 2), (3, 4)].into();
assert_eq!(map1, map2);
Examples
use indexmap::IndexSet;

let set1 = IndexSet::from([1, 2, 3, 4]);
let set2: IndexSet<_> = [1, 2, 3, 4].into();
assert_eq!(set1, set2);

Implementors

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

Convert a DateTime<FixedOffset> instance into a DateTime<Local> instance.

Convert a DateTime<FixedOffset> instance into a DateTime<Utc> instance.

Convert a DateTime<Local> instance into a DateTime<FixedOffset> instance.

Convert a DateTime<Local> instance into a DateTime<Utc> instance.

Convert a DateTime<Utc> instance into a DateTime<FixedOffset> instance.

Convert a DateTime<Utc> instance into a DateTime<Local> instance.

Convert from Result to Either with Ok => Right and Err => Left.

Stability note: This impl does not yet exist, but we are “reserving space” to add it in the future. See rust-lang/rust#64715 for details.

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);