Trait Into
trait Into<T>: Sized
A value-to-value conversion that consumes the input value. The
opposite of From.
One should avoid implementing Into and implement From instead.
Implementing From automatically provides one with an implementation of Into
thanks to the blanket implementation in the standard library.
Prefer using Into over From when specifying trait bounds on a generic function
to ensure that types that only implement Into can be used as well.
Note: This trait must not fail. If the conversion can fail, use TryInto.
Generic Implementations
From<T> for UimpliesInto<U> for TIntois reflexive, which means thatInto<T> for Tis implemented
Implementing Into for conversions to external types in old versions of Rust
Prior to Rust 1.41, if the destination type was not part of the current crate
then you couldn't implement From directly.
For example, take this code:
#
;
This will fail to compile in older versions of the language because Rust's orphaning rules
used to be a little bit more strict. To bypass this, you could implement Into directly:
;
It is important to understand that Into does not provide a From implementation
(as From does with Into). Therefore, you should always try to implement From
and then fall back to Into if From can't be implemented.
Examples
String implements Into<Vec<u8>>:
In order to express that we want a generic function to take all arguments that can be
converted to a specified type T, we can use a trait bound of Into<T>.
For example: The function is_hello takes all arguments that can be converted into a
Vec<u8>.
let s = "hello".to_string;
is_hello;
Required Methods
fn into(self: Self) -> TConverts this type into the (usually inferred) input type.
Implementors
impl<T, U> Into for MapWhile<I, P>impl<T, U> Into for ()impl<T, U> Into for OnceCell<T>impl<T, U> Into for float32x2x2_timpl<T, U> Into for Yeet<T>impl<T, U> Into for uint8x8x4_timpl<T, U> Into for m128impl<T, U> Into for uint16x8x3_timpl<T, U> Into for CharSearcher<'a>impl<T, U> Into for Utf8Chunks<'a>impl<T, U> Into for DebugSet<'a, 'b>impl<T, U> Into for CpuidResultimpl<T, U> Into for MaybeDangling<P>impl<T, U> Into for m256dimpl<T, U> Into for poly64x2x2_timpl<T, U> Into for v128impl<T, U> Into for RChunksExact<'a, T>impl<T, U> Into for uint8x16_timpl<T, U> Into for vector_bool_long_longimpl<T, U> Into for uint16x8x4_timpl<T, U> Into for EscapeDefaultimpl<T, U> Into for float16x4x3_timpl<T, U> Into for PhantomData<T>impl<T, U> Into for Signimpl<T, U> Into for Formatter<'a>impl<T, U> Into for Split<'a, T, P>impl<T, U> Into for CharArrayRefSearcher<'a, 'b, N>impl<T, U> Into for Lastimpl<T, U> Into for Take<I>impl<T, U> Into for Zip<A, B>impl<T, U> Into for SipHasherimpl<T, U> Into for float16x4x4_timpl<T, U> Into for DebugAsHeximpl<T, U> Into for Ready<T>impl<T, U> Into for uint64x2x3_timpl<T, U> Into for NonNull<T>impl<T, U> Into for FromFn<F>impl<T, U> Into for int16x8_timpl<T, U> Into for vector_doubleimpl<T, U> Into for Inspect<I, F>impl<T, U> Into for int16x4x2_timpl<T, U> Into for Variantimpl<T, U> Into for FieldRepresentingType<T, VARIANT, FIELD>impl<T, U> Into for CharPredicateSearcher<'a, F>impl<T, U> Into for uint64x2x4_timpl<T, U> Into for f64impl<T, U> Into for i8impl<T, U> Into for f16x2impl<T, U> Into for SyncUnsafeCell<T>impl<T, U> Into for poly16x8_timpl<T, U> Into for EscapeDefault<'a>impl<T, U> Into for Mask<T, N>impl<T, U> Into for int32x4x2_timpl<T, U> Into for Strimpl<T, U> Into for float64x2x2_timpl<T, U> Into for RangeFrom<Idx>impl<T, U> Into for Windows<'a, T>impl<T, U> Into for RSplitN<'a, P>impl<T, U> Into for IntoIter<A>impl<T, U> Into for poly8x8x3_timpl<T, U> Into for Boolimpl<T, U> Into for Iter<'a, T>impl<T, U> Into for Range<Idx>impl<T, U> Into for Copied<I>impl<T, U> Into for int64x1x2_timpl<T, U> Into for SimdAlignimpl<T, U> Into for StepBy<I>impl<T, U> Into for RSplit<'a, T, P>impl<T, U> Into for Chunks<'a, T>impl<T, U> Into for uint32x4_timpl<T, U> Into for Chain<A, B>impl<T, U> Into for poly8x8x4_timpl<T, U> Into for poly16x8x3_timpl<T, U> Into for vector_unsigned_longimpl<T, U> Into for Referenceimpl<T, U> Into for SocketAddrimpl<T, U> Into for SearchStepimpl<T, U> Into for Pending<T>impl<T, U> Into for CharTryFromErrorimpl<T, U> Into for ChunksMut<'a, T>impl<T, U> Into for u32impl<T, U> Into for ArrayChunks<I, N>impl<T, U> Into for vector_unsigned_charimpl<T, U> Into for Source<'a>impl<T, U> Into for poly16x8x4_timpl<T, U> Into for float32x2x3_timpl<T, U> Into for float64x2_timpl<T, U> Into for ToLowercaseimpl<T, U> Into for FromCoroutine<G>impl<T, U> Into for int64x2_timpl<T, U> Into for Option<T>impl<T, U> Into for vector_doubleimpl<T, U> Into for Pointerimpl<T, U> Into for u8impl<T, U> Into for RawWakerVTableimpl<T, U> Into for RangeInclusiveIter<A>impl<T, U> Into for Reverse<T>impl<T, U> Into for int8x16x2_timpl<T, U> Into for Enumimpl<T, U> Into for MapWindows<I, F, N>impl<T, U> Into for float32x2x4_timpl<T, U> Into for DecodeUtf16<I>impl<T, U> Into for poly64x2x3_timpl<T, U> Into for RSplitN<'a, T, P>impl<T, U> Into for u16impl<T, U> Into for __m128iimpl<T, U> Into for Chars<'a>impl<T, U> Into for objc_selectorimpl<T, U> Into for vector_signed_shortimpl<T, U> Into for Ipv6MulticastScopeimpl<T, U> Into for poly64x2_timpl<T, U> Into for Cloned<I>impl<T, U> Into for uint16x4x2_timpl<T, U> Into for poly64x2x4_timpl<T, U> Into for ChunksExactMut<'a, T>impl<T, U> Into for Map<I, F>impl<T, U> Into for SkipWhile<I, P>impl<T, U> Into for Simd<T, N>impl<T, U> Into for RangeTo<Idx>impl<T, U> Into for int8x8_timpl<T, U> Into for __m128dimpl<T, U> Into for SplitN<'a, P>impl<T, U> Into for vector_bool_shortimpl<T, U> Into for Atomic<T>impl<T, U> Into for uint32x4x2_timpl<T, U> Into for DebugStruct<'a, 'b>impl<T, U> Into for FromBytesUntilNulErrorimpl<T, U> Into for float16x8_timpl<T, U> Into for int16x4x3_timpl<T, U> Into for HvxVectorPairimpl<T, U> Into for StrSearcher<'a, 'b>impl<T, U> Into for Peekable<I>impl<T, U> Into for Scan<I, St, F>impl<T, U> Into for ContextBuilder<'a>impl<T, U> Into for i64impl<T, U> Into for Abiimpl<T, U> Into for PhantomCovariant<T>impl<T, U> Into for uint64x1x2_timpl<T, U> Into for poly8x8_timpl<T, U> Into for __m256impl<T, U> Into for vector_signed_charimpl<T, U> Into for TraitImpl<T>impl<T, U> Into for EscapeUnicode<'a>impl<T, U> Into for int16x4x4_timpl<T, U> Into for AsciiCharimpl<T, U> Into for vector_unsigned_intimpl<T, U> Into for Clamp<Idx>impl<T, U> Into for int32x4x3_timpl<T, U> Into for charimpl<T, U> Into for float64x2x3_timpl<T, U> Into for Layoutimpl<T, U> Into for MatchIndices<'a, P>impl<T, U> Into for Fuse<I>impl<T, U> Into for [MaybeUninit<T>; N]impl<T, U> Into for int32x4x4_timpl<T, U> Into for BasicBlockimpl<T, U> Into for int64x1x3_timpl<T, U> Into for EscapeAscii<'a>impl<T, U> Into for float64x2x4_timpl<T, U> Into for uint16x4_timpl<T, U> Into for OnceWith<F>impl<T, U> Into for __m512iimpl<T, U> Into for vector_bool_charimpl<T, U> Into for vector_floatimpl<T, U> Into for Lifetimeimpl<T, U> Into for PhantomContravariant<T>impl<T, U> Into for EscapeUnicodeimpl<T, U> Into for ParseBoolErrorimpl<T, U> Into for OneSidedRangeBoundimpl<T, U> Into for uint8x16x2_timpl<T, U> Into for objc_classimpl<T, U> Into for BuildHasherDefault<H>impl<T, U> Into for int64x1x4_timpl<T, U> Into for PollFn<F>impl<T, U> Into for LocalWakerimpl<T, U> Into for ToUppercaseimpl<T, U> Into for VaList<'a>impl<T, U> Into for SYimpl<T, U> Into for Fieldimpl<T, U> Into for Filter<I, P>impl<T, U> Into for int32x2_timpl<T, U> Into for __m512dimpl<T, U> Into for vector_unsigned_shortimpl<T, U> Into for poly16x4x2_timpl<T, U> Into for BorrowMutErrorimpl<T, U> Into for SocketAddrV4impl<T, U> Into for RSplitTerminator<'a, P>impl<T, U> Into for int8x16x3_timpl<T, U> Into for FpCategoryimpl<T, U> Into for PhantomInvariantLifetime<'a>impl<T, U> Into for PhantomInvariant<T>impl<T, U> Into for Context<'a>impl<T, U> Into for ByRefSized<'a, I>impl<T, U> Into for TryFromSliceErrorimpl<T, U> Into for Arrayimpl<T, U> Into for TryFromFloatSecsErrorimpl<T, U> Into for float16x8x2_timpl<T, U> Into for Cell<T>impl<T, U> Into for (T)impl<T, U> Into for float32x2_timpl<T, U> Into for __m256bhimpl<T, U> Into for vector_signed_intimpl<T, U> Into for int8x16x4_timpl<T, U> Into for IterMut<'a, A>impl<T, U> Into for uint16x4x3_timpl<T, U> Into for HvxVectorPairimpl<T, U> Into for ArrayWindows<'a, T, N>impl<T, U> Into for i16impl<T, U> Into for FilterMap<I, F>impl<T, U> Into for fn(_: T) -> Retimpl<T, U> Into for FromFn<F>impl<T, U> Into for poly64x1x2_timpl<T, U> Into for TypeKindimpl<T, U> Into for Location<'a>impl<T, U> Into for Enumerate<I>impl<T, U> Into for uint16x4x4_timpl<T, U> Into for Structimpl<T, U> Into for uint32x4x3_timpl<T, U> Into for RChunks<'a, T>impl<T, U> Into for uint64x1_timpl<T, U> Into for __m128himpl<T, U> Into for vector_bool_intimpl<T, U> Into for DebugTuple<'a, 'b>impl<T, U> Into for i128impl<T, U> Into for AtomicOrderingimpl<T, U> Into for EscapeDebugimpl<T, U> Into for Orderingimpl<T, U> Into for m128iimpl<T, U> Into for uint32x4x4_timpl<T, U> Into for uint64x1x3_timpl<T, U> Into for TakeWhile<I, P>impl<T, U> Into for Wakerimpl<T, U> Into for RChunksMut<'a, T>impl<T, U> Into for ParseFloatErrorimpl<T, U> Into for Tupleimpl<T, U> Into for Unionimpl<T, U> Into for Localityimpl<T, U> Into for Charimpl<T, U> Into for RefCell<T>impl<T, U> Into for m256impl<T, U> Into for Skip<I>impl<T, U> Into for IterMut<'a, T>impl<T, U> Into for RawWakerimpl<T, U> Into for RSplitMut<'a, T, P>impl<T, U> Into for UnsafePinned<T>impl<T, U> Into for RangeIter<A>impl<T, U> Into for int8x16_timpl<T, U> Into for __m512himpl<T, U> Into for RMatchIndices<'a, P>impl<T, U> Into for vector_unsigned_long_longimpl<T, U> Into for poly8x16x2_timpl<T, U> Into for PanicInfo<'a>impl<T, U> Into for PhantomContravariantLifetime<'a>impl<T, U> Into for uint64x1x4_timpl<T, U> Into for DropGuard<T, F>impl<T, U> Into for m128dimpl<T, U> Into for CharArraySearcher<'a, N>impl<T, U> Into for BorrowErrorimpl<T, U> Into for SplitTerminator<'a, P>impl<T, U> Into for bf16impl<T, U> Into for SplitInclusive<'a, P>impl<T, U> Into for int32x2x2_timpl<T, U> Into for neverimpl<T, U> Into for Intimpl<T, U> Into for UnwindTerminateReasonimpl<T, U> Into for DebugList<'a, 'b>impl<T, U> Into for float64x1x2_timpl<T, U> Into for Bound<T>impl<T, U> Into for poly8x16_timpl<T, U> Into for vector_floatimpl<T, U> Into for uint8x16x3_timpl<T, U> Into for GenericTypeimpl<T, U> Into for UnsafeCell<T>impl<T, U> Into for RangeInclusive<Idx>impl<T, U> Into for Iter<'a, A>impl<T, U> Into for EncodeUtf16<'a>impl<T, U> Into for CharSliceSearcher<'a, 'b>impl<T, U> Into for float32x4x2_timpl<T, U> Into for SplitNMut<'a, T, P>impl<T, U> Into for RangeToInclusive<Idx>impl<T, U> Into for BorrowedBuf<'data>impl<T, U> Into for uint8x16x4_timpl<T, U> Into for poly16x4x3_timpl<T, U> Into for Flatten<I>impl<T, U> Into for FnPtrimpl<T, U> Into for uint16x8_timpl<T, U> Into for IntErrorKindimpl<T, U> Into for Typeimpl<T, U> Into for LazyCell<T, F>impl<T, U> Into for *const Timpl<T, U> Into for ManuallyDrop<T>impl<T, U> Into for AddrParseErrorimpl<T, U> Into for Assumeimpl<T, U> Into for poly16x4x4_timpl<T, U> Into for float16x8x3_timpl<T, U> Into for Once<T>impl<T, U> Into for Sliceimpl<T, U> Into for i32impl<T, U> Into for ReturnToArgimpl<T, U> Into for Empty<T>impl<T, U> Into for int32x4_timpl<T, U> Into for int8x8x2_timpl<T, U> Into for BorrowedCursor<'a>impl<T, U> Into for Infallibleimpl<T, U> Into for vector_signed_longimpl<T, U> Into for float16x8x4_timpl<T, U> Into for Errorimpl<T, U> Into for ParseCharErrorimpl<T, U> Into for Poll<T>impl<T, U> Into for poly64x1x3_timpl<T, U> Into for Bytes<'a>impl<T, U> Into for SocketAddrV6impl<T, U> Into for Intersperse<I>impl<T, U> Into for ControlFlow<B, C>impl<T, U> Into for Alignmentimpl<T, U> Into for int16x8x2_timpl<T, U> Into for DynTraitimpl<T, U> Into for vector_signed_charimpl<T, U> Into for float64x1_timpl<T, U> Into for poly64x1x4_timpl<T, U> Into for f32impl<T, U> Into for RSplit<'a, P>impl<T, U> Into for float32x4_timpl<T, U> Into for SplitAsciiWhitespace<'a>impl<T, U> Into for vector_bool_longimpl<T, U> Into for ParseIntErrorimpl<T, U> Into for uint32x2x2_timpl<T, U> Into for Rev<T>impl<T, U> Into for AllocErrorimpl<T, U> Into for Matches<'a, P>impl<T, U> Into for poly8x16x3_timpl<T, U> Into for DynTraitPredicateimpl<T, U> Into for vector_bool_charimpl<T, U> Into for AssertUnwindSafe<T>impl<T, U> Into for ChunksExact<'a, T>impl<T, U> Into for RepeatWith<F>impl<T, U> Into for uint64x2_timpl<T, U> Into for u128impl<T, U> Into for PanicMessage<'a>impl<T, U> Into for CoroutineState<Y, R>impl<T, U> Into for int64x2x2_timpl<T, U> Into for RChunksExactMut<'a, T>impl<T, U> Into for Ipv4Addrimpl<T, U> Into for poly8x16x4_timpl<T, U> Into for Saturating<T>impl<T, U> Into for int32x2x3_timpl<T, U> Into for NonZero<T>impl<T, U> Into for float64x1x3_timpl<T, U> Into for __m128impl<T, U> Into for FromBytesWithNulErrorimpl<T, U> Into for RangeFromIter<A>impl<T, U> Into for Repeat<A>impl<T, U> Into for Iter<'a, T>impl<T, U> Into for Traitimpl<T, U> Into for vector_unsigned_shortimpl<T, U> Into for usizeimpl<T, U> Into for Floatimpl<T, U> Into for UnwindActionArgimpl<T, U> Into for RangeFullimpl<T, U> Into for ChunkBy<'a, T, P>impl<T, U> Into for f128impl<T, U> Into for CharIndices<'a>impl<T, U> Into for MaybeUninit<T>impl<T, U> Into for float16x4_timpl<T, U> Into for Lines<'a>impl<T, U> Into for EscapeDebug<'a>impl<T, U> Into for HvxVectorimpl<T, U> Into for int32x2x4_timpl<T, U> Into for Timpl<T, U> Into for Constimpl<T, U> Into for float32x4x3_timpl<T, U> Into for Alignmentimpl<T, U> Into for float64x1x4_timpl<T, U> Into for DecodeUtf16Errorimpl<T, U> Into for TryFromCharErrorimpl<T, U> Into for Successors<T, F>impl<T, U> Into for Ref<'b, T>impl<T, U> Into for ToTitlecaseimpl<T, U> Into for uint8x8_timpl<T, U> Into for __m256iimpl<T, U> Into for uint8x8x2_timpl<T, U> Into for vector_signed_intimpl<T, U> Into for PhantomCovariantLifetime<'a>impl<T, U> Into for PhantomPinnedimpl<T, U> Into for float32x4x4_timpl<T, U> Into for HvxVectorPredimpl<T, U> Into for FormattingOptionsimpl<T, U> Into for CharCaseimpl<T, U> Into for Split<'a, P>impl<T, U> Into for SplitWhitespace<'a>impl<T, U> Into for uint16x8x2_timpl<T, U> Into for int16x4_timpl<T, U> Into for __m256dimpl<T, U> Into for vector_unsigned_charimpl<T, U> Into for int8x8x3_timpl<T, U> Into for OptionFlatten<A>impl<T, U> Into for vector_bool_intimpl<T, U> Into for RefMut<'b, T>impl<T, U> Into for LayoutErrorimpl<T, U> Into for Utf8Errorimpl<T, U> Into for FlatMap<I, U, F>impl<T, U> Into for Exclusive<T>impl<T, U> Into for float16x4x2_timpl<T, U> Into for c_voidimpl<T, U> Into for int8x8x4_timpl<T, U> Into for int16x8x3_timpl<T, U> Into for boolimpl<T, U> Into for SplitN<'a, T, P>impl<T, U> Into for poly16x4_timpl<T, U> Into for u64impl<T, U> Into for __m512impl<T, U> Into for vector_signed_shortimpl<T, U> Into for IntersperseWith<I, G>impl<T, U> Into for uint64x2x2_timpl<T, U> Into for RangeToInclusive<Idx>impl<T, U> Into for Result<T, E>impl<T, U> Into for Wrapping<T>impl<T, U> Into for int16x8x4_timpl<T, U> Into for FromIter<I>impl<T, U> Into for uint32x2x3_timpl<T, U> Into for NumBuffer<T>impl<T, U> Into for Discriminant<T>impl<T, U> Into for TryFromIntErrorimpl<T, U> Into for RangeInclusive<Idx>impl<T, U> Into for RMatches<'a, P>impl<T, U> Into for isizeimpl<T, U> Into for Cycle<I>impl<T, U> Into for Durationimpl<T, U> Into for Arguments<'a>impl<T, U> Into for SplitInclusive<'a, T, P>impl<T, U> Into for uint32x2_timpl<T, U> Into for __m128bhimpl<T, U> Into for vector_bool_shortimpl<T, U> Into for uint32x2x4_timpl<T, U> Into for int64x2x3_timpl<T, U> Into for HvxVectorimpl<T, U> Into for EscapeDefaultimpl<T, U> Into for f16impl<T, U> Into for TypeIdimpl<T, U> Into for DebugMap<'a, 'b>impl<T, U> Into for Range<Idx>impl<T, U> Into for SplitMut<'a, T, P>impl<T, U> Into for RSplitNMut<'a, T, P>impl<T, U> Into for Pin<Ptr>impl<T, U> Into for GetDisjointMutErrorimpl<T, U> Into for IterMut<'a, T>impl<T, U> Into for poly8x8x2_timpl<T, U> Into for int64x2x4_timpl<T, U> Into for ChunkByMut<'a, T, P>impl<T, U> Into for int64x1_timpl<T, U> Into for Bytes<'a>impl<T, U> Into for __m512bhimpl<T, U> Into for vector_unsigned_intimpl<T, U> Into for LinesAny<'a>impl<T, U> Into for Orderingimpl<T, U> Into for HvxVectorPredimpl<T, U> Into for SplitInclusiveMut<'a, T, P>impl<T, U> Into for IntoIter<T>impl<T, U> Into for Utf8Pattern<'a>impl<T, U> Into for poly16x8x2_timpl<T, U> Into for IpAddrimpl<T, U> Into for RepeatN<A>impl<T, U> Into for RangeFrom<Idx>impl<T, U> Into for uint8x8x3_timpl<T, U> Into for Genericimpl<T, U> Into for Utf8Chunk<'a>impl<T, U> Into for m256iimpl<T, U> Into for DynMetadata<Dyn>impl<T, U> Into for Ipv6Addrimpl<T, U> Into for poly64x1_timpl<T, U> Into for __m256himpl<T, U> Into for vector_signed_long_longimpl<T, U> Into for IntoIter<T, N>