Skip to content

Commit 79caaea

Browse files
committed
Allow borrowed ReconstructionSettings constructor args
1 parent 3c90613 commit 79caaea

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

core/src/formatter.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,7 @@ mod tests {
964964
.parser(DelphiLogicalLineParser {})
965965
.file_formatter(IndentBasedOnLineNumber {})
966966
.reconstructor(DelphiLogicalLinesReconstructor::new(
967-
ReconstructionSettings::new("\n".to_owned(), " ".to_owned(), " ".to_owned())
968-
.unwrap(),
967+
ReconstructionSettings::new("\n", " ", " ").unwrap(),
969968
))
970969
.build();
971970
run_test(
@@ -1000,8 +999,7 @@ mod tests {
1000999
.file_formatter(IndentBasedOnLineNumber {})
10011000
.file_formatter(IndentSecondLine3SpacesIfNoNewLine {})
10021001
.reconstructor(DelphiLogicalLinesReconstructor::new(
1003-
ReconstructionSettings::new("\n".to_owned(), " ".to_owned(), " ".to_owned())
1004-
.unwrap(),
1002+
ReconstructionSettings::new("\n", " ", " ").unwrap(),
10051003
))
10061004
.build();
10071005
run_test(
@@ -1054,8 +1052,7 @@ mod tests {
10541052
.file_formatter(IndentSecondLine3SpacesIfNoNewLine {})
10551053
.line_formatter(RetainSpacesLogcialLinesOnNewLines {})
10561054
.reconstructor(DelphiLogicalLinesReconstructor::new(
1057-
ReconstructionSettings::new("\n".to_owned(), " ".to_owned(), " ".to_owned())
1058-
.unwrap(),
1055+
ReconstructionSettings::new("\n", " ", " ").unwrap(),
10591056
))
10601057
.build();
10611058
run_test(

core/src/formatter_selector.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ mod tests {
7272
},
7373
})
7474
.reconstructor(DelphiLogicalLinesReconstructor::new(
75-
ReconstructionSettings::new("\n".to_owned(), "\t".to_owned(), "\r".to_owned())
76-
.unwrap(),
75+
ReconstructionSettings::new("\n", "\t", "\r").unwrap(),
7776
))
7877
.build();
7978
run_test(formatter, "a;", "\ta;\r");

core/src/lang.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -514,15 +514,15 @@ pub struct ReconstructionSettings {
514514
continuation_str: String,
515515
}
516516
impl ReconstructionSettings {
517-
pub fn new(
518-
newline_str: String,
519-
indentation_str: String,
520-
continuation_str: String,
517+
pub fn new<S: Into<String> + AsRef<str>>(
518+
newline_str: S,
519+
indentation_str: S,
520+
continuation_str: S,
521521
) -> Result<Self, InvalidReconstructionSettingsError> {
522522
for (name, val) in &[
523-
("newline", &newline_str),
524-
("indentation", &indentation_str),
525-
("continuation", &continuation_str),
523+
("newline", newline_str.as_ref()),
524+
("indentation", indentation_str.as_ref()),
525+
("continuation", continuation_str.as_ref()),
526526
] {
527527
if val.is_empty() {
528528
return Err(InvalidReconstructionSettingsError::new(format!(
@@ -536,9 +536,9 @@ impl ReconstructionSettings {
536536
}
537537

538538
Ok(ReconstructionSettings {
539-
newline_str,
540-
indentation_str,
541-
continuation_str,
539+
newline_str: newline_str.into(),
540+
indentation_str: indentation_str.into(),
541+
continuation_str: continuation_str.into(),
542542
})
543543
}
544544
pub fn get_newline_str(&self) -> &str {

0 commit comments

Comments
 (0)