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 | |
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')
-rw-r--r-- | src/construct/partial_mdx_expression.rs | 4 | ||||
-rw-r--r-- | src/mdast.rs | 6 | ||||
-rw-r--r-- | src/state.rs | 4 | ||||
-rw-r--r-- | src/to_html.rs | 6 | ||||
-rw-r--r-- | src/to_mdast.rs | 6 | ||||
-rw-r--r-- | src/util/char.rs | 13 | ||||
-rw-r--r-- | src/util/character_reference.rs | 6 | ||||
-rw-r--r-- | src/util/sanitize_uri.rs | 8 |
8 files changed, 23 insertions, 30 deletions
diff --git a/src/construct/partial_mdx_expression.rs b/src/construct/partial_mdx_expression.rs index fbb13e0..f5d1c50 100644 --- a/src/construct/partial_mdx_expression.rs +++ b/src/construct/partial_mdx_expression.rs @@ -62,7 +62,7 @@ use crate::state::{Name as StateName, State}; use crate::tokenizer::Tokenizer; use crate::util::{constant::TAB_SIZE, mdx_collect::collect}; use crate::{MdxExpressionKind, MdxExpressionParse, MdxSignal}; -use alloc::{format, string::ToString}; +use alloc::format; /// Start of an MDX expression. /// @@ -93,7 +93,7 @@ pub fn before(tokenizer: &mut Tokenizer) -> State { "{}:{}: {}", tokenizer.point.line, tokenizer.point.column, tokenizer.tokenize_state.mdx_last_parse_error.take() - .unwrap_or_else(|| "Unexpected end of file in expression, expected a corresponding closing brace for `{`".to_string()) + .unwrap_or_else(|| "Unexpected end of file in expression, expected a corresponding closing brace for `{`".into()) )) } Some(b'\n') => { diff --git a/src/mdast.rs b/src/mdast.rs index 4485167..5e3fca6 100644 --- a/src/mdast.rs +++ b/src/mdast.rs @@ -250,7 +250,7 @@ impl ToString for Node { | Node::Image(_) | Node::ImageReference(_) | Node::ThematicBreak(_) - | Node::Definition(_) => "".to_string(), + | Node::Definition(_) => "".into(), } } } @@ -1152,12 +1152,12 @@ pub struct MdxJsxAttribute { mod tests { use super::*; use crate::unist::{Point, Position}; - use alloc::{string::ToString, vec}; + use alloc::vec; #[test] fn test() { let text = Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position { start: Point { line: 1, diff --git a/src/state.rs b/src/state.rs index 1cc2720..cbe19a7 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,7 +2,7 @@ use crate::construct; use crate::tokenizer::Tokenizer; -use alloc::string::{String, ToString}; +use alloc::string::String; /// Result of a state. #[derive(Clone, Debug, Eq, PartialEq)] @@ -34,7 +34,7 @@ impl State { unreachable!("cannot turn intermediate state into result") } State::Ok => Ok(()), - State::Error(x) => Err(x.to_string()), + State::Error(x) => Err(x.into()), } } } diff --git a/src/to_html.rs b/src/to_html.rs index a0ab152..a851580 100644 --- a/src/to_html.rs +++ b/src/to_html.rs @@ -300,7 +300,7 @@ pub fn compile(events: &[Event], bytes: &[u8], options: &CompileOptions) -> Stri .buffers .get(0) .expect("expected 1 final buffer") - .to_string() + .into() } /// Handle the event at `index`. @@ -690,7 +690,7 @@ fn on_enter_paragraph(context: &mut CompileContext) { /// Handle [`Enter`][Kind::Enter]:[`Resource`][Name::Resource]. fn on_enter_resource(context: &mut CompileContext) { context.buffer(); // We can have line endings in the resource, ignore them. - context.media_stack.last_mut().unwrap().destination = Some("".to_string()); + context.media_stack.last_mut().unwrap().destination = Some("".into()); } /// Handle [`Enter`][Kind::Enter]:[`ResourceDestinationString`][Name::ResourceDestinationString]. @@ -1733,7 +1733,7 @@ fn generate_autolink( let url = if let Some(protocol) = protocol { format!("{}{}", protocol, value) } else { - value.to_string() + value.into() }; let url = if context.options.allow_dangerous_protocol { diff --git a/src/to_mdast.rs b/src/to_mdast.rs index c4650da..fe5bd82 100644 --- a/src/to_mdast.rs +++ b/src/to_mdast.rs @@ -1068,7 +1068,7 @@ fn on_exit_raw_text(context: &mut CompileContext) -> Result<(), String> { } if replace { - value = str::from_utf8(&bytes).unwrap().to_string(); + value = str::from_utf8(&bytes).unwrap().into(); } } @@ -1730,7 +1730,7 @@ fn trim_eol(value: String, at_start: bool, at_end: bool) -> String { } if start > 0 || end < bytes.len() { - str::from_utf8(&bytes[start..end]).unwrap().to_string() + str::from_utf8(&bytes[start..end]).unwrap().into() } else { value } @@ -1762,7 +1762,7 @@ fn on_mismatch_error( if let Some(left) = left { format!(" before the end of `{:?}`", left.name) } else { - "".to_string() + "".into() } )); } 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, }; diff --git a/src/util/character_reference.rs b/src/util/character_reference.rs index ee2a65c..330293c 100644 --- a/src/util/character_reference.rs +++ b/src/util/character_reference.rs @@ -4,7 +4,7 @@ use crate::util::constant::{ CHARACTER_REFERENCES, CHARACTER_REFERENCES_HTML_4, CHARACTER_REFERENCE_DECIMAL_SIZE_MAX, CHARACTER_REFERENCE_HEXADECIMAL_SIZE_MAX, CHARACTER_REFERENCE_NAMED_SIZE_MAX, }; -use alloc::string::{String, ToString}; +use alloc::string::String; use core::str; /// Decode named character references. @@ -89,11 +89,11 @@ pub fn decode_numeric(value: &str, radix: u32) -> String { // Lone surrogates, noncharacters, and out of range are handled by // Rust. ) { - return char.to_string(); + return char.into(); } } - char::REPLACEMENT_CHARACTER.to_string() + char::REPLACEMENT_CHARACTER.into() } /// Decode a character reference. diff --git a/src/util/sanitize_uri.rs b/src/util/sanitize_uri.rs index 7006ace..cd0600d 100644 --- a/src/util/sanitize_uri.rs +++ b/src/util/sanitize_uri.rs @@ -1,11 +1,7 @@ //! Make urls safe. use crate::util::encode::encode; -use alloc::{ - format, - string::{String, ToString}, - vec::Vec, -}; +use alloc::{format, string::String, vec::Vec}; /// Make a value safe for injection as a URL. /// @@ -75,7 +71,7 @@ pub fn sanitize_with_protocols(value: &str, protocols: &[&str]) -> String { // If it is a protocol, it should be allowed. let protocol = value[0..colon].to_lowercase(); if !protocols.contains(&protocol.as_str()) { - return "".to_string(); + return "".into(); } } |