Replace all uses and implementations of new() with default()
This commit is contained in:
parent
315956e20d
commit
6b739d93c2
15 changed files with 100 additions and 84 deletions
|
|
@ -24,7 +24,7 @@ const LEXMAP: LexMap = &[
|
|||
];
|
||||
|
||||
fn lex(text: &str, map: LexMap, config: &Config) -> Vec<Token> {
|
||||
let mut tokens: Vec<Token> = Vec::new();
|
||||
let mut tokens: Vec<Token> = Vec::default();
|
||||
let mut state = state::State::default();
|
||||
|
||||
let segments = segment::segment(text);
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ impl Lexeme {
|
|||
let mut iterator = raw_strings.iter().peekable();
|
||||
|
||||
while let Some(raw) = iterator.next() {
|
||||
let mut next = String::new();
|
||||
let mut next = String::default();
|
||||
let mut last = false;
|
||||
if let Some(peeked) = iterator.peek() {
|
||||
next.clone_from(*peeked);
|
||||
|
|
|
|||
|
|
@ -33,20 +33,20 @@ pub struct AnchorBuffer {
|
|||
impl AnchorBuffer {
|
||||
pub fn clear(&mut self) {
|
||||
self.candidate = Anchor::default();
|
||||
self.text = String::new();
|
||||
self.destination = String::new();
|
||||
self.text = String::default();
|
||||
self.destination = String::default();
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AnchorBuffer {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let display_text = if self.text.is_empty() {
|
||||
String::new()
|
||||
String::default()
|
||||
} else {
|
||||
format!("text: {:?}", self.text)
|
||||
};
|
||||
let display_destination = if self.destination.is_empty() {
|
||||
String::new()
|
||||
String::default()
|
||||
} else {
|
||||
format!(", dest: {:?}", self.destination)
|
||||
};
|
||||
|
|
@ -69,13 +69,13 @@ impl Default for State {
|
|||
inline: Inline::None,
|
||||
block: Block::None,
|
||||
},
|
||||
dom_ids: HashMap::new(),
|
||||
dom_ids: HashMap::default(),
|
||||
switches: Switches { oblique: false },
|
||||
buffers: Buffers {
|
||||
anchor: AnchorBuffer {
|
||||
candidate: Anchor::default(),
|
||||
text: String::new(),
|
||||
destination: String::new(),
|
||||
text: String::default(),
|
||||
destination: String::default(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl std::fmt::Display for Anchor {
|
|||
None => "<unknown>",
|
||||
};
|
||||
|
||||
let mut tail = String::new();
|
||||
let mut tail = String::default();
|
||||
|
||||
if self.leading {
|
||||
tail.push_str(" [Leading]");
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ impl std::fmt::Display for Header {
|
|||
|
||||
let display_dom_id = match self.dom_id {
|
||||
Some(ref dom_id) => format!(" DOM ID {dom_id}"),
|
||||
None => String::new(),
|
||||
None => String::default(),
|
||||
};
|
||||
|
||||
write!(
|
||||
|
|
@ -193,7 +193,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn make_id() {
|
||||
let mut map: HashMap<String, Vec<String>> = HashMap::new();
|
||||
let mut map: HashMap<String, Vec<String>> = HashMap::default();
|
||||
let id = Header::make_id(
|
||||
&Config::default(),
|
||||
&Lexeme::new("##", "Title"),
|
||||
|
|
@ -204,33 +204,33 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn ascii_ids_set() {
|
||||
let mut config = Config::new();
|
||||
let mut config = Config::default();
|
||||
config.ascii_dom_ids = true;
|
||||
|
||||
let id = Header::make_id(
|
||||
&config,
|
||||
&Lexeme::new("##", "駄目!"),
|
||||
&mut HashMap::new(),
|
||||
&mut HashMap::default(),
|
||||
);
|
||||
assert_eq!(id, "h");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ascii_ids_unset() {
|
||||
let mut config = Config::new();
|
||||
let mut config = Config::default();
|
||||
config.ascii_dom_ids = false;
|
||||
|
||||
let id = Header::make_id(
|
||||
&config,
|
||||
&Lexeme::new("##", "駄目!"),
|
||||
&mut HashMap::new(),
|
||||
&mut HashMap::default(),
|
||||
);
|
||||
assert_eq!(id, "駄目!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn id_deduplication() {
|
||||
let mut map: HashMap<String, Vec<String>> = HashMap::new();
|
||||
let mut map: HashMap<String, Vec<String>> = HashMap::default();
|
||||
let config = Config::default();
|
||||
let id =
|
||||
Header::make_id(&config, &Lexeme::new("##", "UVrcCUjoQ"), &mut map);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue