Skip to content

Commit

Permalink
Merge pull request #795 from epage/template
Browse files Browse the repository at this point in the history
chore: Update from _rust template
  • Loading branch information
epage authored Sep 27, 2024
2 parents 0b4cf74 + cbb6c28 commit 0f5fd87
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/action@v3.0.1
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp
PRs should tell a cohesive story, with test and refactor commits that keep the
fix or feature commits simple and clear.

Specifically, we would encouage
Specifically, we would encourage
- File renames be isolated into their own commit
- Add tests in a commit before their feature or fix, showing the current behavior.
The diff for the feature/fix commit will then show how the behavior changed,
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
uninlined_format_args = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
2 changes: 1 addition & 1 deletion crates/benchmarks/benches/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod map {
fn gen(num_entries: usize) -> String {
let mut s = String::new();
for i in 0..num_entries {
s += &format!("[header_no_{}]\n", i);
s += &format!("[header_no_{i}]\n");
s += "entry = 42\n";
}
s
Expand Down
2 changes: 1 addition & 1 deletion crates/toml/examples/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ fn main() {
"#;

let decoded: Config = toml::from_str(toml_str).unwrap();
println!("{:#?}", decoded);
println!("{decoded:#?}");
}
2 changes: 1 addition & 1 deletion crates/toml/examples/enum_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ fn main() {
]"#;

let decoded: Config = toml::from_str(toml_str).unwrap();
println!("{:#?}", decoded);
println!("{decoded:#?}");
}
2 changes: 1 addition & 1 deletion crates/toml/examples/toml2json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
let json = convert(toml);
println!("{}", serde_json::to_string_pretty(&json).unwrap());
}
Err(error) => println!("failed to parse TOML: {}", error),
Err(error) => println!("failed to parse TOML: {error}"),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/toml/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ mod internal {
settings.visit_table_mut(&mut table);

let doc: toml_edit::DocumentMut = table.into();
write!(dst, "{}", doc).unwrap();
write!(dst, "{doc}").unwrap();

Ok(())
}
Expand Down Expand Up @@ -1067,7 +1067,7 @@ mod internal {

let value = value.map_err(Error::wrap)?;

write!(dst, "{}", value).unwrap();
write!(dst, "{value}").unwrap();

Ok(())
}
Expand Down
9 changes: 4 additions & 5 deletions crates/toml/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl<'de> de::Deserialize<'de> for Value {
if let crate::map::Entry::Vacant(vacant) = map.entry(&key) {
vacant.insert(visitor.next_value()?);
} else {
let msg = format!("duplicate key: `{}`", key);
let msg = format!("duplicate key: `{key}`");
return Err(de::Error::custom(msg));
}
}
Expand Down Expand Up @@ -808,7 +808,7 @@ impl<'de> de::VariantAccess<'de> for MapEnumDeserializer {
if values.len() == len {
de::Deserializer::deserialize_seq(values.into_deserializer(), visitor)
} else {
Err(Error::custom(format!("expected tuple with length {}", len)))
Err(Error::custom(format!("expected tuple with length {len}")))
}
}
Value::Table(values) => {
Expand All @@ -818,8 +818,7 @@ impl<'de> de::VariantAccess<'de> for MapEnumDeserializer {
.map(|(index, (key, value))| match key.parse::<usize>() {
Ok(key_index) if key_index == index => Ok(value),
Ok(_) | Err(_) => Err(Error::custom(format!(
"expected table key `{}`, but was `{}`",
index, key
"expected table key `{index}`, but was `{key}`"
))),
})
.collect();
Expand All @@ -828,7 +827,7 @@ impl<'de> de::VariantAccess<'de> for MapEnumDeserializer {
if tuple_values.len() == len {
de::Deserializer::deserialize_seq(tuple_values.into_deserializer(), visitor)
} else {
Err(Error::custom(format!("expected tuple with length {}", len)))
Err(Error::custom(format!("expected tuple with length {len}")))
}
}
e => Err(Error::custom(format!(
Expand Down
2 changes: 1 addition & 1 deletion crates/toml/tests/testsuite/spanned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn test_spanned_field() {
);

for expected in good_datetimes() {
let s = format!("foo = {}", expected);
let s = format!("foo = {expected}");
good::<Datetime>(&s, expected, None);
}
// ending at something other than the absolute end
Expand Down
8 changes: 4 additions & 4 deletions crates/toml_datetime/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ impl From<Time> for Datetime {
impl fmt::Display for Datetime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref date) = self.date {
write!(f, "{}", date)?;
write!(f, "{date}")?;
}
if let Some(ref time) = self.time {
if self.date.is_some() {
write!(f, "T")?;
}
write!(f, "{}", time)?;
write!(f, "{time}")?;
}
if let Some(ref offset) = self.offset {
write!(f, "{}", offset)?;
write!(f, "{offset}")?;
}
Ok(())
}
Expand Down Expand Up @@ -282,7 +282,7 @@ impl fmt::Display for Offset {
}
let hours = minutes / 60;
let minutes = minutes % 60;
write!(f, "{}{:02}:{:02}", sign, hours, minutes)
write!(f, "{sign}{hours:02}:{minutes:02}")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/toml_edit/examples/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn main() {

println!("** visit_mut example");
visit_mut_example(&mut document);
println!("{}", document);
println!("{document}");
}

#[cfg(test)]
Expand Down Expand Up @@ -280,5 +280,5 @@ fn visit_mut_correct() {
let mut document: DocumentMut = INPUT.parse().expect("input is valid TOML");

visit_mut_example(&mut document);
assert_eq!(format!("{}", document), VISIT_MUT_OUTPUT);
assert_eq!(format!("{document}"), VISIT_MUT_OUTPUT);
}
4 changes: 2 additions & 2 deletions crates/toml_edit/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Array {
pub fn replace_formatted(&mut self, index: usize, v: Value) -> Value {
match mem::replace(&mut self.values[index], Item::Value(v)) {
Item::Value(old_value) => old_value,
x => panic!("non-value item {:?} in an array", x),
x => panic!("non-value item {x:?} in an array"),
}
}

Expand All @@ -307,7 +307,7 @@ impl Array {
let removed = self.values.remove(index);
match removed {
Item::Value(v) => v,
x => panic!("non-value item {:?} in an array", x),
x => panic!("non-value item {x:?} in an array"),
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/toml_edit/src/de/table_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
)
} else {
Err(Error::custom(
format!("expected tuple with length {}", len),
format!("expected tuple with length {len}"),
values_span,
))
}
Expand All @@ -90,7 +90,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
)
} else {
Err(Error::custom(
format!("expected tuple with length {}", len),
format!("expected tuple with length {len}"),
values_span,
))
}
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
)
} else {
Err(Error::custom(
format!("expected tuple with length {}", len),
format!("expected tuple with length {len}"),
values_span,
))
}
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
)
} else {
Err(Error::custom(
format!("expected tuple with length {}", len),
format!("expected tuple with length {len}"),
values_span,
))
}
Expand Down
8 changes: 4 additions & 4 deletions crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) fn encode_key(this: &Key, buf: &mut dyn Write, input: Option<&str>) -
repr.encode(buf, input)?;
} else {
let repr = this.display_repr();
write!(buf, "{}", repr)?;
write!(buf, "{repr}")?;
};

Ok(())
Expand Down Expand Up @@ -109,7 +109,7 @@ pub(crate) fn encode_formatted<T: ValueRepr>(
repr.encode(buf, input)?;
} else {
let repr = this.display_repr();
write!(buf, "{}", repr)?;
write!(buf, "{repr}")?;
};

decor.suffix_encode(buf, input, default_decor.1)?;
Expand Down Expand Up @@ -533,9 +533,9 @@ fn to_f64_repr(f: f64) -> Repr {
(false, false, true) => "0.0".to_owned(),
(_, false, false) => {
if f % 1.0 == 0.0 {
format!("{}.0", f)
format!("{f}.0")
} else {
format!("{}", f)
format!("{f}")
}
}
};
Expand Down
10 changes: 3 additions & 7 deletions crates/toml_edit/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,16 @@ impl Display for TomlError {
// Allow highlight to go one past the line
let highlight_len = highlight_len.min(content.len().saturating_sub(column));

writeln!(
f,
"TOML parse error at line {}, column {}",
line_num, col_num
)?;
writeln!(f, "TOML parse error at line {line_num}, column {col_num}")?;
// |
for _ in 0..=gutter {
write!(f, " ")?;
}
writeln!(f, "|")?;

// 1 | 00:32:00.a999999
write!(f, "{} | ", line_num)?;
writeln!(f, "{}", content)?;
write!(f, "{line_num} | ")?;
writeln!(f, "{content}")?;

// | ^
for _ in 0..=gutter {
Expand Down
9 changes: 4 additions & 5 deletions crates/toml_edit/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,20 @@ impl Display for CustomError {
CustomError::DuplicateKey { key, table } => {
if let Some(table) = table {
if table.is_empty() {
write!(f, "duplicate key `{}` in document root", key)
write!(f, "duplicate key `{key}` in document root")
} else {
let path = table.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
write!(f, "duplicate key `{}` in table `{}`", key, path)
write!(f, "duplicate key `{key}` in table `{path}`")
}
} else {
write!(f, "duplicate key `{}`", key)
write!(f, "duplicate key `{key}`")
}
}
CustomError::DottedKeyExtendWrongType { key, actual } => {
let path = key.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
write!(
f,
"dotted key `{}` attempted to extend non-table type ({})",
path, actual
"dotted key `{path}` attempted to extend non-table type ({actual})"
)
}
CustomError::OutOfRange => write!(f, "value is out of range"),
Expand Down
12 changes: 3 additions & 9 deletions crates/toml_edit/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ key = "value"
let doc = match parsed {
Ok(doc) => doc,
Err(err) => {
panic!(
"Parse error: {:?}\nFailed to parse:\n```\n{}\n```",
err, input
)
panic!("Parse error: {err:?}\nFailed to parse:\n```\n{input}\n```")
}
};

Expand All @@ -251,10 +248,7 @@ authors = []
match parsed {
Ok(_) => (),
Err(err) => {
panic!(
"Parse error: {:?}\nFailed to parse:\n```\n{}\n```",
err, input
)
panic!("Parse error: {err:?}\nFailed to parse:\n```\n{input}\n```")
}
}
}
Expand All @@ -267,7 +261,7 @@ $"#];
for input in invalid_inputs {
dbg!(input);
let parsed = parse_document(input).map(|d| d.into_mut());
assert!(parsed.is_err(), "Input: {:?}", input);
assert!(parsed.is_err(), "Input: {input:?}");
}
}
}
2 changes: 1 addition & 1 deletion crates/toml_edit/src/parser/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ mod test {

let overflow = "9e99999";
let parsed = float.parse(new_input(overflow));
assert!(parsed.is_err(), "{:?}", parsed);
assert!(parsed.is_err(), "{parsed:?}");
}
}
}
2 changes: 1 addition & 1 deletion crates/toml_edit/src/parser/trivia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod test {
for input in inputs {
dbg!(input);
let parsed = ws_comment_newline.take().parse(new_input(input));
assert!(parsed.is_ok(), "{:?}", parsed);
assert!(parsed.is_ok(), "{parsed:?}");
let parsed = parsed.unwrap();
assert_eq!(parsed, input.as_bytes());
}
Expand Down
Loading

0 comments on commit 0f5fd87

Please sign in to comment.