From c9f1162a6ffc81adcb114a616899edad0f7d0750 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Mon, 4 May 2020 10:17:39 +0100 Subject: Rephrase the any::type_name docs a bit. This attempts to be a little clearer (including in terminology) about the lack of guarantees that any::type_name provides. --- src/libcore/any.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 39df803bbea..67698e5409f 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -446,14 +446,14 @@ impl TypeId { /// # Note /// /// This is intended for diagnostic use. The exact contents and format of the -/// string are not specified, other than being a best-effort description of the -/// type. For example, `type_name::>()` could return the -/// `"Option"` or `"std::option::Option"`, but not -/// `"foobar"`. In addition, the output may change between versions of the -/// compiler. +/// string retrned are not specified, other than being a best-effort description +/// of the type. For example, amongst the strings +/// that `type_name::>()` might map to are `"Option"` and +/// `"std::option::Option"`. /// -/// The type name should not be considered a unique identifier of a type; -/// multiple types may share the same type name. +/// The returned string must not be considered to be a unique identifier of a +/// type as multiple types may map to the same type name. In addition, the +/// output may change between versions of the compiler. /// /// The current implementation uses the same infrastructure as compiler /// diagnostics and debuginfo, but this is not guaranteed. -- cgit 1.4.1-3-g733a5 From 93f877ce870e9fd13ad7c6a05ccb4abd46a3d106 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Mon, 4 May 2020 11:01:31 +0100 Subject: Document that lifetimes do not currently appear in any::type_name()'s output. --- src/libcore/any.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 67698e5409f..2628f890332 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -452,7 +452,9 @@ impl TypeId { /// `"std::option::Option"`. /// /// The returned string must not be considered to be a unique identifier of a -/// type as multiple types may map to the same type name. In addition, the +/// type as multiple types may map to the same type name. Similarly, there is no +/// guarantee that all parts of a type will appear in the returned string: for +/// example, lifetime specifiers are currently not included. In addition, the /// output may change between versions of the compiler. /// /// The current implementation uses the same infrastructure as compiler -- cgit 1.4.1-3-g733a5 From 876001c8ac331a15661638fbb18b8b64facf2c96 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Mon, 4 May 2020 14:28:58 +0100 Subject: Fix typo. --- src/libcore/any.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 2628f890332..996a9cdfc4d 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -446,8 +446,8 @@ impl TypeId { /// # Note /// /// This is intended for diagnostic use. The exact contents and format of the -/// string retrned are not specified, other than being a best-effort description -/// of the type. For example, amongst the strings +/// string returned are not specified, other than being a best-effort +/// description of the type. For example, amongst the strings /// that `type_name::>()` might map to are `"Option"` and /// `"std::option::Option"`. /// -- cgit 1.4.1-3-g733a5 From 5cb2fa487bf6405a18c13041bc18544884f603a7 Mon Sep 17 00:00:00 2001 From: Dolpheyn Date: Mon, 4 May 2020 22:14:25 +0800 Subject: Document From trait for Option implementations --- src/libcore/option.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 63a5277100f..a87f3c1804c 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1357,12 +1357,38 @@ impl<'a, T> IntoIterator for &'a mut Option { #[stable(since = "1.12.0", feature = "option_from")] impl From for Option { + /// Copies val to a new Option::Some + /// + /// # Examples + /// + /// ``` + /// let o: Option = Option::from(67); + /// assert_eq!(Some(67), o); + /// ``` fn from(val: T) -> Option { Some(val) } } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] + /// Converts from &Option to Option<&T> + /// + /// # Examples + /// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, preserving the original. + /// The [`map`] method takes the `self` argument by value, consuming the original, + /// so this technique uses `as_ref` to first take an `Option` to a reference + /// to the value inside the original. + /// + /// [`map`]: enum.Option.html#method.map + /// [`String`]: ../../std/string/struct.String.html + /// [`usize`]: ../../std/primitive.usize.html + /// + /// ``` + /// let s: Option = Some(String::from("Hello, Rustaceans!")); + /// let o: Option = Option::from(&s).map(|ss: &String| ss.len()); + /// println!("Can still print s: {}", s); + /// assert_eq!(o, Some(18)); + /// ``` impl<'a, T> From<&'a Option> for Option<&'a T> { fn from(o: &'a Option) -> Option<&'a T> { o.as_ref() @@ -1371,6 +1397,19 @@ impl<'a, T> From<&'a Option> for Option<&'a T> { #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] impl<'a, T> From<&'a mut Option> for Option<&'a mut T> { + /// Converts from &mut Option to Option<&mut T> + /// + /// # Examples + /// + /// ``` + /// let mut s = Some(String::from("Hello")); + /// let o: Option<&mut String> = Option::from(&mut s); + /// match o { + /// Some(t) => *t = String::from("Hello, Rustaceans!"), + /// None => (), + /// } + /// assert_eq!(s, Some(String::from("Hello, Rustaceans!"))); + /// ``` fn from(o: &'a mut Option) -> Option<&'a mut T> { o.as_mut() } -- cgit 1.4.1-3-g733a5 From 73f07a47b892216c47a741e229924b90a86585e1 Mon Sep 17 00:00:00 2001 From: Dolpheyn Date: Tue, 5 May 2020 08:25:20 +0800 Subject: Fix comment position --- src/libcore/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index a87f3c1804c..480fe4fd4be 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1371,6 +1371,7 @@ impl From for Option { } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] +impl<'a, T> From<&'a Option> for Option<&'a T> { /// Converts from &Option to Option<&T> /// /// # Examples @@ -1389,7 +1390,6 @@ impl From for Option { /// println!("Can still print s: {}", s); /// assert_eq!(o, Some(18)); /// ``` -impl<'a, T> From<&'a Option> for Option<&'a T> { fn from(o: &'a Option) -> Option<&'a T> { o.as_ref() } -- cgit 1.4.1-3-g733a5 From 2badd41d043c9ff549855ad832e7bcd2ad44970d Mon Sep 17 00:00:00 2001 From: Dolpheyn Date: Tue, 5 May 2020 09:50:59 +0800 Subject: Fix example --- src/libcore/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 480fe4fd4be..4647ad01006 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1387,7 +1387,7 @@ impl<'a, T> From<&'a Option> for Option<&'a T> { /// ``` /// let s: Option = Some(String::from("Hello, Rustaceans!")); /// let o: Option = Option::from(&s).map(|ss: &String| ss.len()); - /// println!("Can still print s: {}", s); + /// println!("Can still print s: {:?}", s); /// assert_eq!(o, Some(18)); /// ``` fn from(o: &'a Option) -> Option<&'a T> { -- cgit 1.4.1-3-g733a5 From d80ac6416d1a6b38756e18c5b5ea421bbd11dfba Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Sun, 10 May 2020 18:06:30 +0800 Subject: Fix link to `map` documentation in example Co-authored-by: Timo --- src/libcore/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 4647ad01006..4df9eaa4815 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1380,7 +1380,7 @@ impl<'a, T> From<&'a Option> for Option<&'a T> { /// so this technique uses `as_ref` to first take an `Option` to a reference /// to the value inside the original. /// - /// [`map`]: enum.Option.html#method.map + /// [`map`]: ../../std/option/enum.Option.html#method.map /// [`String`]: ../../std/string/struct.String.html /// [`usize`]: ../../std/primitive.usize.html /// -- cgit 1.4.1-3-g733a5 From 003ed802c4a289d959d4212ad80f33df7f3e2bc3 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Tue, 12 May 2020 16:54:29 +0100 Subject: Map to -> return. --- src/libcore/any.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 996a9cdfc4d..79b6304958d 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -448,7 +448,7 @@ impl TypeId { /// This is intended for diagnostic use. The exact contents and format of the /// string returned are not specified, other than being a best-effort /// description of the type. For example, amongst the strings -/// that `type_name::>()` might map to are `"Option"` and +/// that `type_name::>()` might return are `"Option"` and /// `"std::option::Option"`. /// /// The returned string must not be considered to be a unique identifier of a -- cgit 1.4.1-3-g733a5 From 46e9cbea3a65aff70c838ebbd157d715ee84718b Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:04:52 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 4df9eaa4815..542115763c2 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1357,7 +1357,7 @@ impl<'a, T> IntoIterator for &'a mut Option { #[stable(since = "1.12.0", feature = "option_from")] impl From for Option { - /// Copies val to a new Option::Some + /// Copies `val` into a new `Some`. /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From 4588c26e53a39f0379a0f25ace4228bc207f4a73 Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:05:53 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 542115763c2..515040dd4cc 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1363,6 +1363,7 @@ impl From for Option { /// /// ``` /// let o: Option = Option::from(67); + /// /// assert_eq!(Some(67), o); /// ``` fn from(val: T) -> Option { -- cgit 1.4.1-3-g733a5 From a9e7d572380c271848f1137f39ef09257144bd37 Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:12:35 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 515040dd4cc..3e64177a467 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1373,7 +1373,7 @@ impl From for Option { #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] impl<'a, T> From<&'a Option> for Option<&'a T> { - /// Converts from &Option to Option<&T> + /// Converts from `&Option` to `Option<&T>`. /// /// # Examples /// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, preserving the original. -- cgit 1.4.1-3-g733a5 From 644bb24e335bd15c7c90a2c31afa63d9ba5f5dbc Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:12:50 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 3e64177a467..848560bd795 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1405,6 +1405,7 @@ impl<'a, T> From<&'a mut Option> for Option<&'a mut T> { /// ``` /// let mut s = Some(String::from("Hello")); /// let o: Option<&mut String> = Option::from(&mut s); + /// /// match o { /// Some(t) => *t = String::from("Hello, Rustaceans!"), /// None => (), -- cgit 1.4.1-3-g733a5 From adc2bf0cfe3f4c6611ebcd80b570ed8ebd76b548 Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:13:08 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 848560bd795..340637a55f7 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1376,6 +1376,7 @@ impl<'a, T> From<&'a Option> for Option<&'a T> { /// Converts from `&Option` to `Option<&T>`. /// /// # Examples + /// /// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, preserving the original. /// The [`map`] method takes the `self` argument by value, consuming the original, /// so this technique uses `as_ref` to first take an `Option` to a reference -- cgit 1.4.1-3-g733a5 From f445a8286e4d889ac33935768f2ac0823b2c01ba Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:13:17 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 340637a55f7..a6a8d4bd7e1 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1399,7 +1399,7 @@ impl<'a, T> From<&'a Option> for Option<&'a T> { #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] impl<'a, T> From<&'a mut Option> for Option<&'a mut T> { - /// Converts from &mut Option to Option<&mut T> + /// Converts from `&mut Option` to `Option<&mut T>` /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From ef1688db8e33b635287462854b7203f86c7acbf5 Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:13:27 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index a6a8d4bd7e1..ebaa4894862 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1411,6 +1411,7 @@ impl<'a, T> From<&'a mut Option> for Option<&'a mut T> { /// Some(t) => *t = String::from("Hello, Rustaceans!"), /// None => (), /// } + /// /// assert_eq!(s, Some(String::from("Hello, Rustaceans!"))); /// ``` fn from(o: &'a mut Option) -> Option<&'a mut T> { -- cgit 1.4.1-3-g733a5 From 6c3856f3ec5bbcd1c748d01a463f04a8fef0bd6c Mon Sep 17 00:00:00 2001 From: Faris Sufyan <47665123+Dolpheyn@users.noreply.github.com> Date: Wed, 13 May 2020 21:13:35 +0800 Subject: Update src/libcore/option.rs Co-authored-by: Steve Klabnik --- src/libcore/option.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index ebaa4894862..e8483875c97 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1389,7 +1389,9 @@ impl<'a, T> From<&'a Option> for Option<&'a T> { /// ``` /// let s: Option = Some(String::from("Hello, Rustaceans!")); /// let o: Option = Option::from(&s).map(|ss: &String| ss.len()); + /// /// println!("Can still print s: {:?}", s); + /// /// assert_eq!(o, Some(18)); /// ``` fn from(o: &'a Option) -> Option<&'a T> { -- cgit 1.4.1-3-g733a5