about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github35764891676564198441@oli-obk.de>2024-02-14 11:53:40 +0100
committerGitHub <noreply@github.com>2024-02-14 11:53:40 +0100
commitc1a80211f5a38cc08d79ec90f25d29aa4271c76a (patch)
tree8e5b37e2e7ad161276e07b616fa5187746d86a5d
parentbad2cb08dea2b271db728f52d8dc354d0b38a4e6 (diff)
parent1c7ea307cfd58bd428d10e3d05681ce3058ce4a9 (diff)
downloadrust-c1a80211f5a38cc08d79ec90f25d29aa4271c76a.tar.gz
rust-c1a80211f5a38cc08d79ec90f25d29aa4271c76a.zip
Rollup merge of #121024 - joseluis:feat-asciichar-default, r=scottmcm
implement `Default` for `AsciiChar`

This implements `Default` for `AsciiChar` in order to match `char`'s implementation.

From all the different possible ways to do this I think the clearest one is to have both `char` and `AsciiChar` impls together.

I've also updated the doc-comment of the default variant since rustdoc doesn't seem to indicate it otherwise. Probably the text could be improved, though. I couldn't find any similar examples in the codebase and suggestions are welcomed.

r? `@scottmcm`
-rw-r--r--library/core/src/ascii/ascii_char.rs2
-rw-r--r--library/core/src/default.rs3
2 files changed, 4 insertions, 1 deletions
diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs
index 5f758af1624..34a05ac3888 100644
--- a/library/core/src/ascii/ascii_char.rs
+++ b/library/core/src/ascii/ascii_char.rs
@@ -58,7 +58,7 @@ use crate::mem::transmute;
 #[unstable(feature = "ascii_char", issue = "110998")]
 #[repr(u8)]
 pub enum AsciiChar {
-    /// U+0000
+    /// U+0000 (The default variant)
     #[unstable(feature = "ascii_char_variants", issue = "110998")]
     Null = 0,
     /// U+0001
diff --git a/library/core/src/default.rs b/library/core/src/default.rs
index 16618b38769..a1303fcd821 100644
--- a/library/core/src/default.rs
+++ b/library/core/src/default.rs
@@ -2,6 +2,8 @@
 
 #![stable(feature = "rust1", since = "1.0.0")]
 
+use crate::ascii::Char as AsciiChar;
+
 /// A trait for giving a type a useful default value.
 ///
 /// Sometimes, you want to fall back to some kind of default value, and
@@ -158,6 +160,7 @@ macro_rules! default_impl {
 default_impl! { (), (), "Returns the default value of `()`" }
 default_impl! { bool, false, "Returns the default value of `false`" }
 default_impl! { char, '\x00', "Returns the default value of `\\x00`" }
+default_impl! { AsciiChar, AsciiChar::Null, "Returns the default value of `Null`" }
 
 default_impl! { usize, 0, "Returns the default value of `0`" }
 default_impl! { u8, 0, "Returns the default value of `0`" }