Movatterモバイル変換


[0]ホーム

URL:


Module convert

core

Moduleconvert 

1.6.0 ·Source
Expand description

Traits for conversions between types.

The traits in this module provide a way to convert from one type to another type.Each trait serves a different purpose:

  • Implement theAsRef trait for cheap reference-to-reference conversions
  • Implement theAsMut trait for cheap mutable-to-mutable conversions
  • Implement theFrom trait for consuming value-to-value conversions
  • Implement theInto trait for consuming value-to-value conversions to typesoutside the current crate
  • TheTryFrom andTryInto traits behave likeFrom andInto,but should be implemented when the conversion can fail.

The traits in this module are often used as trait bounds for generic functions such that toarguments of multiple types are supported. See the documentation of each trait for examples.

As a library author, you should always prefer implementingFrom<T> orTryFrom<T> rather thanInto<U> orTryInto<U>,asFrom andTryFrom provide greater flexibility and offerequivalentInto orTryInto implementations for free, thanks to ablanket implementation in the standard library. When targeting a version prior to Rust 1.41, itmay be necessary to implementInto orTryInto directly when converting to a typeoutside the current crate.

§Generic Implementations

See each trait for usage examples.

Enums§

Infallible
The error type for errors that can never happen.

Traits§

AsMut
Used to do a cheap mutable-to-mutable reference conversion.
AsRef
Used to do a cheap reference-to-reference conversion.
From
Used to do value-to-value conversions while consuming the input value. It is the reciprocal ofInto.
Into
A value-to-value conversion that consumes the input value. Theopposite ofFrom.
TryFrom
Simple and safe type conversions that may fail in a controlledway under some circumstances. It is the reciprocal ofTryInto.
TryInto
An attempted conversion that consumesself, which may or may not beexpensive.
FloatToIntExperimental
Supporting trait for inherent methods off32 andf64 such asto_int_unchecked.Typically doesn’t need to be used directly.

Functions§

identity
The identity function.

[8]ページ先頭

©2009-2025 Movatter.jp