@@ -4709,30 +4709,56 @@ pub use num::dec2flt::ParseFloatError;
4709
4709
// Conversions T -> T are covered by a blanket impl and therefore excluded
4710
4710
// Some conversions from and to usize/isize are not implemented due to portability concerns
4711
4711
macro_rules! impl_from {
4712
- ( $Small: ty, $Large: ty, #[ $attr: meta] ) => {
4712
+ ( $Small: ty, $Large: ty, #[ $attr: meta] , $doc : expr ) => {
4713
4713
#[ $attr]
4714
+ #[ doc = $doc]
4714
4715
impl From <$Small> for $Large {
4715
4716
#[ inline]
4716
4717
fn from( small: $Small) -> $Large {
4717
4718
small as $Large
4718
4719
}
4719
4720
}
4721
+ } ;
4722
+ ( $Small: ty, $Large: ty, #[ $attr: meta] ) => {
4723
+ impl_from!( $Small,
4724
+ $Large,
4725
+ #[ $attr] ,
4726
+ concat!( "Converts `" ,
4727
+ stringify!( $Small) ,
4728
+ "` to `" ,
4729
+ stringify!( $Large) ,
4730
+ "` losslessly." ) ) ;
4720
4731
}
4721
4732
}
4722
4733
4734
+ macro_rules! impl_from_bool {
4735
+ ( $target: ty, #[ $attr: meta] ) => {
4736
+ impl_from!( bool , $target, #[ $attr] , concat!( "Converts a `bool` to a `" ,
4737
+ stringify!( $target) , "`. The resulting value is `0` for `false` and `1` for `true`
4738
+ values.
4739
+
4740
+ # Examples
4741
+
4742
+ ```
4743
+ assert_eq!(" , stringify!( $target) , "::from(true), 1);
4744
+ assert_eq!(" , stringify!( $target) , "::from(false), 0);
4745
+ ```" ) ) ;
4746
+ } ;
4747
+ }
4748
+
4723
4749
// Bool -> Any
4724
- impl_from ! { bool , u8 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4725
- impl_from ! { bool , u16 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4726
- impl_from ! { bool , u32 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4727
- impl_from ! { bool , u64 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4728
- impl_from ! { bool , u128 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4729
- impl_from ! { bool , usize , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4730
- impl_from ! { bool , i8 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4731
- impl_from ! { bool , i16 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4732
- impl_from ! { bool , i32 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4733
- impl_from ! { bool , i64 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4734
- impl_from ! { bool , i128 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4735
- impl_from ! { bool , isize , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4750
+ impl_from_bool ! { u8 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4751
+ impl_from_bool ! { u16 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4752
+ impl_from_bool ! { u32 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4753
+ impl_from_bool ! { u64 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4754
+ impl_from_bool ! { u128 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4755
+ impl_from_bool ! { usize , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4756
+ impl_from_bool ! { i8 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4757
+ impl_from_bool ! { i16 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4758
+ impl_from_bool ! { i32 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4759
+ impl_from_bool ! { i64 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4760
+ impl_from_bool ! { i128 , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4761
+ impl_from_bool ! { isize , #[ stable( feature = "from_bool" , since = "1.28.0" ) ] }
4736
4762
4737
4763
// Unsigned -> Unsigned
4738
4764
impl_from ! { u8 , u16 , #[ stable( feature = "lossless_int_conv" , since = "1.5.0" ) ] }
0 commit comments