Skip to content

Rollup of 7 pull requests #58799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1fd2f16
Have all methods of Filter and FilterMap use internal iteration
timvermeulen Feb 25, 2019
4cfe141
Put Local, Static and Promoted as one Base variant of Place
spastorino Feb 22, 2019
d89c2f6
Use informational target machine for metadata
nagisa Feb 20, 2019
8884771
Add relevant benchmarks
timvermeulen Feb 27, 2019
ec2e4ba
Improve existing benchmarks to prevent extreme optimizations
timvermeulen Feb 27, 2019
88bd624
Add trailing newline
timvermeulen Feb 27, 2019
932fe17
rust-lldb: fix crash when printing empty string
euclio Feb 22, 2019
d2b1212
Started expanding docs for `TryFrom` and `TryInto`.
icefoxen Jan 31, 2019
1253227
Add basic docs to integer TryFrom impl macros.
icefoxen Jan 31, 2019
c1d1c67
Fix a bunch of heckin' trailing whitespace
icefoxen Feb 1, 2019
cc6f394
Fix some links in TryFrom docs.
icefoxen Feb 13, 2019
72afe51
Slowly figuring out how rustdoc actually works.
icefoxen Feb 14, 2019
60cf413
Incorporated review changes.
icefoxen Feb 27, 2019
5dce719
Vastly simplify TryFrom docs.
icefoxen Feb 27, 2019
b70a953
Replace `s` with `self` in docs for str methods taking self.
tspiteri Feb 20, 2019
a998b1f
allow specifying attributes for tool lints
euclio Feb 27, 2019
1671ce2
Rollup merge of #58015 - icefoxen:tryfrom-docs, r=SimonSapin
Centril Feb 28, 2019
0f6636b
Rollup merge of #58605 - nagisa:fix-the-metadata, r=michaelwoerister
Centril Feb 28, 2019
acc2bca
Rollup merge of #58629 - euclio:debug-empty-str, r=alexcrichton
Centril Feb 28, 2019
b332e77
Rollup merge of #58631 - spastorino:place2_1, r=oli-obk
Centril Feb 28, 2019
12be658
Rollup merge of #58730 - timvermeulen:internal_iteration, r=scottmcm
Centril Feb 28, 2019
c307b9a
Rollup merge of #58782 - tspiteri:str-escape-self, r=kennytm
Centril Feb 28, 2019
dadf786
Rollup merge of #58785 - euclio:tool-lint-attrs, r=estebank
Centril Feb 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Started expanding docs for TryFrom and TryInto.
The examples are still lacking for now, both for module docs
and for methods/impl's.
icefoxen authored and SimonSapin committed Feb 27, 2019
commit d2b1212558b25e69eb867402792d5b5b5a07ad19
44 changes: 43 additions & 1 deletion src/libcore/convert.rs
Original file line number Diff line number Diff line change
@@ -366,6 +366,11 @@ pub trait From<T>: Sized {
/// provides an equivalent `TryInto` implementation for free, thanks to a
/// blanket implementation in the standard library. For more information on this,
/// see the documentation for [`Into`].
///
/// # Implementing `TryInto`
///
/// This suffers the same restrictions and reasoning as implementing
/// [`Into`], see there for details.
///
/// [`TryFrom`]: trait.TryFrom.html
/// [`Into`]: trait.Into.html
@@ -380,7 +385,44 @@ pub trait TryInto<T>: Sized {
fn try_into(self) -> Result<T, Self::Error>;
}

/// Attempt to construct `Self` via a conversion.
/// Simple and safe type conversions that may fail in a controlled
/// way under some circumstances. It is the reciprocal of [`TryInto`].
///
/// This is useful when you are doing a type conversion that may
/// trivially succeed but may also need special handling.
/// For example, there is no way to convert an `i64` into an `i32`
/// using the [`From`] trait, because an `i64` may contain a value
/// that an `i32` cannot represent and so the conversion would lose data.
/// This might be handled by truncating the `i64` to an `i32` (essentially
/// giving the `i64`'s value modulo `i32::MAX`) or by simply returning
/// `i32::MAX`, or by some other method. The `From` trait is intended
/// for lossless conversions, so the `TryFrom` trait informs the
/// programmer when a type conversion could go bad and lets them
/// decide how to handle it.
///
/// # Generic Implementations
///
/// - `TryFrom<T> for U` implies [`TryInto<U>`]` for T`
/// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
/// is implemented
///
/// # Examples
///
/// As described, [`i32`] implements `TryFrom<i64>`:
///
/// ```
/// let big_number = 1_000_000_000_000i64;
/// // Silently truncates `big_number`, requires detecting
/// // and handling the truncation after the fact.
/// let smaller_number = big_number as i32;
/// assert_eq!(smaller_number, -727379968);
///
/// let try_smaller_number = i32::try_from(big_number);
/// assert!(try_smaller_number.is_err());
///
/// let try_successful_smaller_number = i32::try_from(3);
/// assert!(try_successful_smaller_number.is_ok());
/// ```
#[stable(feature = "try_from", since = "1.34.0")]
pub trait TryFrom<T>: Sized {
/// The type returned in the event of a conversion error.