docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

core::convert

本页内容

API 参考只有英文版,由标准库源代码中的英文文档注释生成。

conversion traits and primitive impls. Four policies, each named at the call: lossless into, fallible try_into (throws TryFrom::Error, OverflowError for numbers), saturating_into, and wrapping_into (= as).

Not trait Into<T> { fn into(self) -> T; }: a blanket impl<T, U: From<T>> Into<U> for T cannot fix U from the receiver, so each *Into trait has one generic method (T from the expected type, like parse) and one blanket impl; the conversions are the *From impls. SaturatingFrom / WrappingFrom back the last two policies. The lossless impls are also nabi.cast.* intrinsics; their bodies are the same as.

Traits

FromSource

pub trait From<U>

A lossless conversion from U.

  • fn from(value: U) -> Self§

    Source

    Converts value without loss.

IntoSource

pub trait Into

x.into() = T::from(x); T from the expected type.

  • fn into<T: From<Self>>(self) -> T§

    Source

    Converts self to T through T::from.

TryFromSource

pub trait TryFrom<U>

A conversion that can fail. Error is what it throws: ConversionError unless the impl names another (the numeric impls say OverflowError).

TryIntoSource

pub trait TryInto

x.try_into() = T::try_from(x); throws T's Error.

  • fn try_into<T: TryFrom<Self>>(self) throws (T::Error) -> T§

    Source

    Converts self to T through T::try_from; throws T::Error when the value does not fit.

SaturatingFromSource

pub trait SaturatingFrom<U>

Out-of-range values clamp to the nearest end.

  • fn saturating_from(value: U) -> Self§

    Source

    Converts value, clamping it to the nearest end of Self's range.

SaturatingIntoSource

pub trait SaturatingInto

x.saturating_into() = T::saturating_from(x); T from the expected type.

WrappingFromSource

pub trait WrappingFrom<U>

Keep the low bits - as spelled as a method.

  • fn wrapping_from(value: U) -> Self§

    Source

    Converts value, keeping the low bits that fit in Self.

WrappingIntoSource

pub trait WrappingInto

x.wrapping_into() = T::wrapping_from(x); T from the expected type.

  • fn wrapping_into<T: WrappingFrom<Self>>(self) -> T§

    Source

    Converts self to T through T::wrapping_from.

AsBytesSource

pub trait AsBytes

Bytes as a view: a str (its UTF-8), a List<u8>, a Slice<u8>, a [u8; N] or a crypto::Secret. Every byte parameter in the library takes <B: AsBytes>.

  • fn byte_slice(self) -> Slice<u8>§

    Source

    The bytes as a view (no copy).