diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-11 15:45:50 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-11 15:45:50 +0200 |
commit | 73d8609565b808ac73df5ac34e6d4f7f23c25ad6 (patch) | |
tree | 8b13c61bcd55380b36338473a74e172b63fb16d7 /src/util/char.rs | |
parent | 070b3efeeebf34fbc435ffc7fea2bad95689664a (diff) | |
download | markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.tar.gz markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.tar.bz2 markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.zip |
Refactor to use a bunch of `into`
Diffstat (limited to 'src/util/char.rs')
-rw-r--r-- | src/util/char.rs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/util/char.rs b/src/util/char.rs index b902fbe..70367f3 100644 --- a/src/util/char.rs +++ b/src/util/char.rs @@ -1,10 +1,7 @@ //! Deal with bytes, chars, and kinds. use crate::util::unicode::PUNCTUATION; -use alloc::{ - format, - string::{String, ToString}, -}; +use alloc::{format, string::String}; use core::str; /// Character kinds. @@ -119,7 +116,7 @@ pub fn classify_opt(char_opt: Option<char>) -> Kind { /// Format an optional `char` (`none` means eof). pub fn format_opt(char: Option<char>) -> String { match char { - None => "end of file".to_string(), + None => "end of file".into(), Some(char) => format!("character {}", format(char)), } } @@ -127,7 +124,7 @@ pub fn format_opt(char: Option<char>) -> String { /// Format an optional `byte` (`none` means eof). pub fn format_byte_opt(byte: Option<u8>) -> String { match byte { - None => "end of file".to_string(), + None => "end of file".into(), Some(byte) => format!("byte {}", format_byte(byte)), } } @@ -136,7 +133,7 @@ pub fn format_byte_opt(byte: Option<u8>) -> String { pub fn format(char: char) -> String { let representation = format!("U+{:>04X}", char as u32); let printable = match char { - '`' => Some("`` ` ``".to_string()), + '`' => Some("`` ` ``".into()), '!'..='~' => Some(format!("`{}`", char)), _ => None, }; @@ -152,7 +149,7 @@ pub fn format(char: char) -> String { pub fn format_byte(byte: u8) -> String { let representation = format!("U+{:>04X}", byte); let printable = match byte { - b'`' => Some("`` ` ``".to_string()), + b'`' => Some("`` ` ``".into()), b'!'..=b'~' => Some(format!("`{}`", str::from_utf8(&[byte]).unwrap())), _ => None, }; |