diff options
| author | Simon Heath <icefoxen@gmail.com> | 2019-01-30 20:19:01 -0500 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2019-02-27 16:02:25 +0100 |
| commit | 12532277d5bde13c19d3b40d34c07ec78c79ff71 (patch) | |
| tree | 434d07c12b905e27a9bd35a76d323ccb8ebe6430 /src/libcore | |
| parent | d2b1212558b25e69eb867402792d5b5b5a07ad19 (diff) | |
| download | rust-12532277d5bde13c19d3b40d34c07ec78c79ff71.tar.gz rust-12532277d5bde13c19d3b40d34c07ec78c79ff71.zip | |
Add basic docs to integer TryFrom impl macros.
They're not as good as `From` 'cause they don't stringify the types and generate examples and so on, but it's a start.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/num/mod.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 3ceba83afee..39a1b48e076 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4544,6 +4544,9 @@ macro_rules! try_from_unbounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to create the target type from the source type. + /// This particular variant will never fail, but is included + /// for completeness's sake. #[inline] fn try_from(value: $source) -> Result<Self, Self::Error> { Ok(value as $target) @@ -4559,6 +4562,10 @@ macro_rules! try_from_lower_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to create a target number type from a + /// source type that has `source::MIN > dest::MIN`. + /// Will return an error if `source` is less than + /// `dest::MIN`. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u >= 0 { @@ -4578,6 +4585,10 @@ macro_rules! try_from_upper_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to create a target number type from a + /// source type that has `source::MAX > dest::MAX`. + /// Will return an error if `source` is greater than + /// `dest::MAX`. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { if u > (<$target>::max_value() as $source) { @@ -4597,6 +4608,11 @@ macro_rules! try_from_both_bounded { impl TryFrom<$source> for $target { type Error = TryFromIntError; + /// Try to "narrow" a number from the source type + /// to the target type. Will return an error if + /// the source value is either larger than the + /// `MAX` value for the target type or smaller + /// than the `MIN` value for it. #[inline] fn try_from(u: $source) -> Result<$target, TryFromIntError> { let min = <$target>::min_value() as $source; |
