From 73d8609565b808ac73df5ac34e6d4f7f23c25ad6 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 11 Oct 2022 15:45:50 +0200 Subject: Refactor to use a bunch of `into` --- src/util/char.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/util/char.rs') 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) -> Kind { /// Format an optional `char` (`none` means eof). pub fn format_opt(char: Option) -> 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) -> String { /// Format an optional `byte` (`none` means eof). pub fn format_byte_opt(byte: Option) -> 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) -> 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, }; -- cgit