@@ -4544,9 +4544,14 @@ macro_rules! try_from_unbounded {
4544
4544
impl TryFrom <$source> for $target {
4545
4545
type Error = TryFromIntError ;
4546
4546
4547
- /// Try to create the target type from the source type.
4548
- /// This particular variant will never fail, but is included
4549
- /// for completeness's sake.
4547
+ /// Try to create the target number type from a source
4548
+ /// number type. If the source type has a larger range
4549
+ /// than the target, or their ranges are disjoint (such
4550
+ /// as converting a signed to unsigned number or vice
4551
+ /// versa), this will return `None` if the source value
4552
+ /// doesn't fit into the range of the destination value.
4553
+ /// If the conversion can never fail, this is still
4554
+ /// implemented for completeness's sake.
4550
4555
#[ inline]
4551
4556
fn try_from( value: $source) -> Result <Self , Self :: Error > {
4552
4557
Ok ( value as $target)
@@ -4562,10 +4567,14 @@ macro_rules! try_from_lower_bounded {
4562
4567
impl TryFrom <$source> for $target {
4563
4568
type Error = TryFromIntError ;
4564
4569
4565
- /// Try to create a target number type from a
4566
- /// source type that has `source::MIN > dest::MIN`.
4567
- /// Will return an error if `source` is less than
4568
- /// `dest::MIN`.
4570
+ /// Try to create the target number type from a source
4571
+ /// number type. If the source type has a larger range
4572
+ /// than the target, or their ranges are disjoint (such
4573
+ /// as converting a signed to unsigned number or vice
4574
+ /// versa), this will return `None` if the source value
4575
+ /// doesn't fit into the range of the destination value.
4576
+ /// If the conversion can never fail, this is still
4577
+ /// implemented for completeness's sake.
4569
4578
#[ inline]
4570
4579
fn try_from( u: $source) -> Result <$target, TryFromIntError > {
4571
4580
if u >= 0 {
@@ -4585,10 +4594,14 @@ macro_rules! try_from_upper_bounded {
4585
4594
impl TryFrom <$source> for $target {
4586
4595
type Error = TryFromIntError ;
4587
4596
4588
- /// Try to create a target number type from a
4589
- /// source type that has `source::MAX > dest::MAX`.
4590
- /// Will return an error if `source` is greater than
4591
- /// `dest::MAX`.
4597
+ /// Try to create the target number type from a source
4598
+ /// number type. If the source type has a larger range
4599
+ /// than the target, or their ranges are disjoint (such
4600
+ /// as converting a signed to unsigned number or vice
4601
+ /// versa), this will return `None` if the source value
4602
+ /// doesn't fit into the range of the destination value.
4603
+ /// If the conversion can never fail, this is still
4604
+ /// implemented for completeness's sake.
4592
4605
#[ inline]
4593
4606
fn try_from( u: $source) -> Result <$target, TryFromIntError > {
4594
4607
if u > ( <$target>:: max_value( ) as $source) {
@@ -4608,11 +4621,14 @@ macro_rules! try_from_both_bounded {
4608
4621
impl TryFrom <$source> for $target {
4609
4622
type Error = TryFromIntError ;
4610
4623
4611
- /// Try to "narrow" a number from the source type
4612
- /// to the target type. Will return an error if
4613
- /// the source value is either larger than the
4614
- /// `MAX` value for the target type or smaller
4615
- /// than the `MIN` value for it.
4624
+ /// Try to create the target number type from a source
4625
+ /// number type. If the source type has a larger range
4626
+ /// than the target, or their ranges are disjoint (such
4627
+ /// as converting a signed to unsigned number or vice
4628
+ /// versa), this will return `None` if the source value
4629
+ /// doesn't fit into the range of the destination value.
4630
+ /// If the conversion can never fail, this is still
4631
+ /// implemented for completeness's sake.
4616
4632
#[ inline]
4617
4633
fn try_from( u: $source) -> Result <$target, TryFromIntError > {
4618
4634
let min = <$target>:: min_value( ) as $source;
0 commit comments