core::convert
本页内容
- Traits
From1Into1TryFrom1TryInto1SaturatingFrom1SaturatingInto1WrappingFrom1WrappingInto1AsBytes1
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.
Converts
valuewithout loss.
IntoSource
pub trait Intox.into() = T::from(x); T from the expected type.
Converts
selftoTthroughT::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).
Sourcetype Error = ConversionError§valueconverted; throws when it cannot be.
TryIntoSource
pub trait TryIntox.try_into() = T::try_from(x); throws T's Error.
Converts
selftoTthroughT::try_from; throwsT::Errorwhen the value does not fit.
SaturatingFromSource
pub trait SaturatingFrom<U>Out-of-range values clamp to the nearest end.
Converts
value, clamping it to the nearest end ofSelf's range.
SaturatingIntoSource
pub trait SaturatingIntox.saturating_into() = T::saturating_from(x); T from the
expected type.
Sourcefn saturating_into<T: SaturatingFrom<Self>>(§self) -> T Converts
selftoTthroughT::saturating_from.
WrappingFromSource
pub trait WrappingFrom<U>Keep the low bits - as spelled as a method.
Converts
value, keeping the low bits that fit inSelf.
WrappingIntoSource
pub trait WrappingIntox.wrapping_into() = T::wrapping_from(x); T from the
expected type.
Sourcefn wrapping_into<T: WrappingFrom<Self>>(§self) -> T Converts
selftoTthroughT::wrapping_from.
AsBytesSource
pub trait AsBytesBytes 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>.
The bytes as a view (no copy).