Skip to content

Commit

Permalink
Rollup merge of #121024 - joseluis:feat-asciichar-default, r=scottmcm
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
oli-obk authored Feb 14, 2024
2 parents bad2cb0 + 1c7ea30 commit c1a8021
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/core/src/ascii/ascii_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`" }
Expand Down

0 comments on commit c1a8021

Please sign in to comment.