Skip to content

Commit

Permalink
Gather all ZST structs of str together
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Sep 26, 2020
1 parent 653b5bf commit 37cd79c
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ use iter::{MatchesInternal, SplitNInternal};

use validations::truncate_to_char_boundary;

impl_fn_for_zst! {
/// A nameable, cloneable fn type
#[derive(Clone)]
struct LinesAnyMap impl<'a> Fn = |line: &'a str| -> &'a str {
let l = line.len();
if l > 0 && line.as_bytes()[l - 1] == b'\r' { &line[0 .. l - 1] }
else { line }
};
}

#[inline(never)]
#[cold]
#[track_caller]
Expand Down Expand Up @@ -2425,22 +2415,6 @@ impl str {
}
}

impl_fn_for_zst! {
#[derive(Clone)]
struct CharEscapeDebugContinue impl Fn = |c: char| -> char::EscapeDebug {
c.escape_debug_ext(false)
};

#[derive(Clone)]
struct CharEscapeUnicode impl Fn = |c: char| -> char::EscapeUnicode {
c.escape_unicode()
};
#[derive(Clone)]
struct CharEscapeDefault impl Fn = |c: char| -> char::EscapeDefault {
c.escape_default()
};
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<[u8]> for str {
#[inline]
Expand All @@ -2467,6 +2441,28 @@ impl Default for &mut str {
}

impl_fn_for_zst! {
/// A nameable, cloneable fn type
#[derive(Clone)]
struct LinesAnyMap impl<'a> Fn = |line: &'a str| -> &'a str {
let l = line.len();
if l > 0 && line.as_bytes()[l - 1] == b'\r' { &line[0 .. l - 1] }
else { line }
};

#[derive(Clone)]
struct CharEscapeDebugContinue impl Fn = |c: char| -> char::EscapeDebug {
c.escape_debug_ext(false)
};

#[derive(Clone)]
struct CharEscapeUnicode impl Fn = |c: char| -> char::EscapeUnicode {
c.escape_unicode()
};
#[derive(Clone)]
struct CharEscapeDefault impl Fn = |c: char| -> char::EscapeDefault {
c.escape_default()
};

#[derive(Clone)]
struct IsWhitespace impl Fn = |c: char| -> bool {
c.is_whitespace()
Expand Down

0 comments on commit 37cd79c

Please sign in to comment.