Replace all uses and implementations of new() with default()

This commit is contained in:
Juno Takano 2026-01-05 13:16:46 -03:00
commit 6b739d93c2
15 changed files with 100 additions and 84 deletions

View file

@ -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);

View file

@ -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(),
},
},
}

View file

@ -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]");

View file

@ -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);