A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html below:

mod.rs - source

1#![stable(feature = "rust1", since = "1.0.0")]
37
38use crate::error::Error;
39use crate::fmt;
40use crate::hash::{Hash, Hasher};
41use crate::marker::PointeeSized;
42
43mod num;
44
45#[unstable(feature = "convert_float_to_int", issue = "67057")]
46pub use num::FloatToInt;
47
48#[stable(feature = "convert_id", since = "1.33.0")]
102#[rustc_const_stable(feature = "const_identity", since = "1.33.0")]
103#[inline(always)]
104#[rustc_diagnostic_item = "convert_identity"]
105pub const fn identity<T>(x: T) -> T {
106    x
107}
108
109#[stable(feature = "rust1", since = "1.0.0")]
218#[rustc_diagnostic_item = "AsRef"]
219#[const_trait]
220#[rustc_const_unstable(feature = "const_try", issue = "74935")]
221pub trait AsRef<T: PointeeSized>: PointeeSized {
222    #[stable(feature = "rust1", since = "1.0.0")]
224    fn as_ref(&self) -> &T;
225}
226
227#[stable(feature = "rust1", since = "1.0.0")]
371#[rustc_diagnostic_item = "AsMut"]
372#[const_trait]
373#[rustc_const_unstable(feature = "const_try", issue = "74935")]
374pub trait AsMut<T: PointeeSized>: PointeeSized {
375    #[stable(feature = "rust1", since = "1.0.0")]
377    fn as_mut(&mut self) -> &mut T;
378}
379
380#[rustc_diagnostic_item = "Into"]
450#[stable(feature = "rust1", since = "1.0.0")]
451#[doc(search_unbox)]
452#[rustc_const_unstable(feature = "const_from", issue = "143773")]
453#[const_trait]
454pub trait Into<T>: Sized {
455    #[must_use]
457    #[stable(feature = "rust1", since = "1.0.0")]
458    fn into(self) -> T;
459}
460
461#[rustc_diagnostic_item = "From"]
583#[stable(feature = "rust1", since = "1.0.0")]
584#[rustc_on_unimplemented(on(
585    all(Self = "&str", T = "alloc::string::String"),
586    note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
587))]
588#[doc(search_unbox)]
589#[rustc_const_unstable(feature = "const_from", issue = "143773")]
590#[const_trait]
591pub trait From<T>: Sized {
592    #[rustc_diagnostic_item = "from_fn"]
594    #[must_use]
595    #[stable(feature = "rust1", since = "1.0.0")]
596    fn from(value: T) -> Self;
597}
598
599#[rustc_diagnostic_item = "TryInto"]
617#[stable(feature = "try_from", since = "1.34.0")]
618#[rustc_const_unstable(feature = "const_from", issue = "143773")]
619#[const_trait]
620pub trait TryInto<T>: Sized {
621    #[stable(feature = "try_from", since = "1.34.0")]
623    type Error;
624
625    #[stable(feature = "try_from", since = "1.34.0")]
627    fn try_into(self) -> Result<T, Self::Error>;
628}
629
630#[rustc_diagnostic_item = "TryFrom"]
697#[stable(feature = "try_from", since = "1.34.0")]
698#[rustc_const_unstable(feature = "const_from", issue = "143773")]
699#[const_trait]
700pub trait TryFrom<T>: Sized {
701    #[stable(feature = "try_from", since = "1.34.0")]
703    type Error;
704
705    #[stable(feature = "try_from", since = "1.34.0")]
707    #[rustc_diagnostic_item = "try_from_fn"]
708    fn try_from(value: T) -> Result<Self, Self::Error>;
709}
710
711#[stable(feature = "rust1", since = "1.0.0")]
717#[rustc_const_unstable(feature = "const_try", issue = "74935")]
718impl<T: PointeeSized, U: PointeeSized> const AsRef<U> for &T
719where
720    T: [const] AsRef<U>,
721{
722    #[inline]
723    fn as_ref(&self) -> &U {
724        <T as AsRef<U>>::as_ref(*self)
725    }
726}
727
728#[stable(feature = "rust1", since = "1.0.0")]
730#[rustc_const_unstable(feature = "const_try", issue = "74935")]
731impl<T: PointeeSized, U: PointeeSized> const AsRef<U> for &mut T
732where
733    T: [const] AsRef<U>,
734{
735    #[inline]
736    fn as_ref(&self) -> &U {
737        <T as AsRef<U>>::as_ref(*self)
738    }
739}
740
741#[stable(feature = "rust1", since = "1.0.0")]
751#[rustc_const_unstable(feature = "const_try", issue = "74935")]
752impl<T: PointeeSized, U: PointeeSized> const AsMut<U> for &mut T
753where
754    T: [const] AsMut<U>,
755{
756    #[inline]
757    fn as_mut(&mut self) -> &mut U {
758        (*self).as_mut()
759    }
760}
761
762#[stable(feature = "rust1", since = "1.0.0")]
772#[rustc_const_unstable(feature = "const_from", issue = "143773")]
773impl<T, U> const Into<U> for T
774where
775    U: [const] From<T>,
776{
777    #[inline]
782    #[track_caller]
783    fn into(self) -> U {
784        U::from(self)
785    }
786}
787
788#[stable(feature = "rust1", since = "1.0.0")]
790#[rustc_const_unstable(feature = "const_from", issue = "143773")]
791impl<T> const From<T> for T {
792    #[inline(always)]
794    fn from(t: T) -> T {
795        t
796    }
797}
798
799#[stable(feature = "convert_infallible", since = "1.34.0")]
805#[rustc_reservation_impl = "permitting this impl would forbid us from adding \
806                            `impl<T> From<!> for T` later; see rust-lang/rust#64715 for details"]
807#[rustc_const_unstable(feature = "const_from", issue = "143773")]
808impl<T> const From<!> for T {
809    fn from(t: !) -> T {
810        t
811    }
812}
813
814#[stable(feature = "try_from", since = "1.34.0")]
816#[rustc_const_unstable(feature = "const_from", issue = "143773")]
817impl<T, U> const TryInto<U> for T
818where
819    U: [const] TryFrom<T>,
820{
821    type Error = U::Error;
822
823    #[inline]
824    fn try_into(self) -> Result<U, U::Error> {
825        U::try_from(self)
826    }
827}
828
829#[stable(feature = "try_from", since = "1.34.0")]
832#[rustc_const_unstable(feature = "const_from", issue = "143773")]
833impl<T, U> const TryFrom<U> for T
834where
835    U: [const] Into<T>,
836{
837    type Error = Infallible;
838
839    #[inline]
840    fn try_from(value: U) -> Result<Self, Self::Error> {
841        Ok(U::into(value))
842    }
843}
844
845#[stable(feature = "rust1", since = "1.0.0")]
850#[rustc_const_unstable(feature = "const_try", issue = "74935")]
851impl<T> const AsRef<[T]> for [T] {
852    #[inline(always)]
853    fn as_ref(&self) -> &[T] {
854        self
855    }
856}
857
858#[stable(feature = "rust1", since = "1.0.0")]
859#[rustc_const_unstable(feature = "const_try", issue = "74935")]
860impl<T> const AsMut<[T]> for [T] {
861    #[inline(always)]
862    fn as_mut(&mut self) -> &mut [T] {
863        self
864    }
865}
866
867#[stable(feature = "rust1", since = "1.0.0")]
868#[rustc_const_unstable(feature = "const_try", issue = "74935")]
869impl const AsRef<str> for str {
870    #[inline(always)]
871    fn as_ref(&self) -> &str {
872        self
873    }
874}
875
876#[stable(feature = "as_mut_str_for_str", since = "1.51.0")]
877#[rustc_const_unstable(feature = "const_try", issue = "74935")]
878impl const AsMut<str> for str {
879    #[inline(always)]
880    fn as_mut(&mut self) -> &mut str {
881        self
882    }
883}
884
885#[stable(feature = "convert_infallible", since = "1.34.0")]
935#[derive(Copy)]
936pub enum Infallible {}
937
938#[stable(feature = "convert_infallible", since = "1.34.0")]
939#[rustc_const_unstable(feature = "const_try", issue = "74935")]
940impl const Clone for Infallible {
941    fn clone(&self) -> Infallible {
942        match *self {}
943    }
944}
945
946#[stable(feature = "convert_infallible", since = "1.34.0")]
947impl fmt::Debug for Infallible {
948    fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
949        match *self {}
950    }
951}
952
953#[stable(feature = "convert_infallible", since = "1.34.0")]
954impl fmt::Display for Infallible {
955    fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
956        match *self {}
957    }
958}
959
960#[stable(feature = "str_parse_error2", since = "1.8.0")]
961impl Error for Infallible {
962    fn description(&self) -> &str {
963        match *self {}
964    }
965}
966
967#[stable(feature = "convert_infallible", since = "1.34.0")]
968#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
969impl const PartialEq for Infallible {
970    fn eq(&self, _: &Infallible) -> bool {
971        match *self {}
972    }
973}
974
975#[stable(feature = "convert_infallible", since = "1.34.0")]
976impl Eq for Infallible {}
977
978#[stable(feature = "convert_infallible", since = "1.34.0")]
979impl PartialOrd for Infallible {
980    fn partial_cmp(&self, _other: &Self) -> Option<crate::cmp::Ordering> {
981        match *self {}
982    }
983}
984
985#[stable(feature = "convert_infallible", since = "1.34.0")]
986impl Ord for Infallible {
987    fn cmp(&self, _other: &Self) -> crate::cmp::Ordering {
988        match *self {}
989    }
990}
991
992#[stable(feature = "convert_infallible", since = "1.34.0")]
993#[rustc_const_unstable(feature = "const_try", issue = "74935")]
994impl const From<!> for Infallible {
995    #[inline]
996    fn from(x: !) -> Self {
997        x
998    }
999}
1000
1001#[stable(feature = "convert_infallible_hash", since = "1.44.0")]
1002impl Hash for Infallible {
1003    fn hash<H: Hasher>(&self, _: &mut H) {
1004        match *self {}
1005    }
1006}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4