Skip to content

Commit c95d6ba

Browse files
authored
fix(clippy/fmt): ran clippy + cargo fmt (#129)
1 parent 564d4ae commit c95d6ba

File tree

8 files changed

+66
-70
lines changed

8 files changed

+66
-70
lines changed

src/document.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl KdlDocument {
210210

211211
/// Length of this document when rendered as a string.
212212
pub fn len(&self) -> usize {
213-
format!("{}", self).len()
213+
format!("{self}").len()
214214
}
215215

216216
/// Returns true if this document is completely empty (including whitespace)
@@ -347,7 +347,7 @@ impl KdlDocument {
347347
pub fn parse(s: &str) -> Result<Self, KdlError> {
348348
#[cfg(not(feature = "v1-fallback"))]
349349
{
350-
KdlDocument::parse_v2(s)
350+
Self::parse_v2(s)
351351
}
352352
#[cfg(feature = "v1-fallback")]
353353
{
@@ -457,7 +457,7 @@ impl KdlDocument {
457457
#[cfg(feature = "v1")]
458458
impl From<kdlv1::KdlDocument> for KdlDocument {
459459
fn from(value: kdlv1::KdlDocument) -> Self {
460-
KdlDocument {
460+
Self {
461461
nodes: value.nodes().iter().map(|x| x.clone().into()).collect(),
462462
format: Some(KdlDocumentFormat {
463463
leading: value.leading().unwrap_or("").into(),
@@ -522,7 +522,7 @@ impl std::str::FromStr for KdlDocument {
522522
type Err = KdlError;
523523

524524
fn from_str(s: &str) -> Result<Self, Self::Err> {
525-
KdlDocument::parse(s)
525+
Self::parse(s)
526526
}
527527
}
528528

@@ -539,13 +539,13 @@ impl KdlDocument {
539539
indent: usize,
540540
) -> std::fmt::Result {
541541
if let Some(KdlDocumentFormat { leading, .. }) = self.format() {
542-
write!(f, "{}", leading)?;
542+
write!(f, "{leading}")?;
543543
}
544544
for node in &self.nodes {
545545
node.stringify(f, indent)?;
546546
}
547547
if let Some(KdlDocumentFormat { trailing, .. }) = self.format() {
548-
write!(f, "{}", trailing)?;
548+
write!(f, "{trailing}")?;
549549
}
550550
Ok(())
551551
}

src/entry.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl std::hash::Hash for KdlEntry {
4141
impl KdlEntry {
4242
/// Creates a new Argument (positional) KdlEntry.
4343
pub fn new(value: impl Into<KdlValue>) -> Self {
44-
KdlEntry {
44+
Self {
4545
ty: None,
4646
value: value.into(),
4747
name: None,
@@ -129,7 +129,7 @@ impl KdlEntry {
129129

130130
/// Creates a new Property (key/value) KdlEntry.
131131
pub fn new_prop(key: impl Into<KdlIdentifier>, value: impl Into<KdlValue>) -> Self {
132-
KdlEntry {
132+
Self {
133133
ty: None,
134134
value: value.into(),
135135
name: Some(key.into()),
@@ -153,7 +153,7 @@ impl KdlEntry {
153153

154154
/// Length of this entry when rendered as a string.
155155
pub fn len(&self) -> usize {
156-
format!("{}", self).len()
156+
format!("{self}").len()
157157
}
158158

159159
/// Returns true if this entry is completely empty (including whitespace).
@@ -385,7 +385,7 @@ impl KdlEntry {
385385
#[cfg(feature = "v1")]
386386
impl From<kdlv1::KdlEntry> for KdlEntry {
387387
fn from(value: kdlv1::KdlEntry) -> Self {
388-
KdlEntry {
388+
Self {
389389
ty: value.ty().map(|x| x.clone().into()),
390390
value: value.value().clone().into(),
391391
name: value.name().map(|x| x.clone().into()),
@@ -404,29 +404,29 @@ impl From<kdlv1::KdlEntry> for KdlEntry {
404404
impl Display for KdlEntry {
405405
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
406406
if let Some(KdlEntryFormat { leading, .. }) = &self.format {
407-
write!(f, "{}", leading)?;
407+
write!(f, "{leading}")?;
408408
}
409409
if let Some(name) = &self.name {
410-
write!(f, "{}", name)?;
410+
write!(f, "{name}")?;
411411
if let Some(KdlEntryFormat {
412412
after_key,
413413
after_eq,
414414
..
415415
}) = &self.format
416416
{
417-
write!(f, "{}={}", after_key, after_eq)?;
417+
write!(f, "{after_key}={after_eq}")?;
418418
} else {
419419
write!(f, "=")?;
420420
}
421421
}
422422
if let Some(ty) = &self.ty {
423423
write!(f, "(")?;
424424
if let Some(KdlEntryFormat { before_ty_name, .. }) = &self.format {
425-
write!(f, "{}", before_ty_name)?;
425+
write!(f, "{before_ty_name}")?;
426426
}
427-
write!(f, "{}", ty)?;
427+
write!(f, "{ty}")?;
428428
if let Some(KdlEntryFormat { after_ty_name, .. }) = &self.format {
429-
write!(f, "{}", after_ty_name)?;
429+
write!(f, "{after_ty_name}")?;
430430
}
431431
write!(f, ")")?;
432432
}
@@ -436,12 +436,12 @@ impl Display for KdlEntry {
436436
..
437437
}) = &self.format
438438
{
439-
write!(f, "{}{}", after_ty, value_repr)?;
439+
write!(f, "{after_ty}{value_repr}")?;
440440
} else {
441441
write!(f, "{}", self.value)?;
442442
}
443443
if let Some(KdlEntryFormat { trailing, .. }) = &self.format {
444-
write!(f, "{}", trailing)?;
444+
write!(f, "{trailing}")?;
445445
}
446446
Ok(())
447447
}
@@ -452,7 +452,7 @@ where
452452
T: Into<KdlValue>,
453453
{
454454
fn from(value: T) -> Self {
455-
KdlEntry::new(value)
455+
Self::new(value)
456456
}
457457
}
458458

@@ -462,15 +462,15 @@ where
462462
V: Into<KdlValue>,
463463
{
464464
fn from((key, value): (K, V)) -> Self {
465-
KdlEntry::new_prop(key, value)
465+
Self::new_prop(key, value)
466466
}
467467
}
468468

469469
impl FromStr for KdlEntry {
470470
type Err = KdlError;
471471

472472
fn from_str(s: &str) -> Result<Self, Self::Err> {
473-
KdlEntry::parse(s)
473+
Self::parse(s)
474474
}
475475
}
476476

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Diagnostic for KdlDiagnostic {
121121
impl From<kdlv1::KdlError> for KdlError {
122122
fn from(value: kdlv1::KdlError) -> Self {
123123
let input = Arc::new(value.input);
124-
KdlError {
124+
Self {
125125
input: input.clone(),
126126
diagnostics: vec![KdlDiagnostic {
127127
input,

src/fmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct FormatConfigBuilder<'a>(FormatConfig<'a>);
4343
impl<'a> FormatConfigBuilder<'a> {
4444
/// Creates a new [`FormatConfig`] builder with default configuration.
4545
pub const fn new() -> Self {
46-
FormatConfigBuilder(FormatConfig {
46+
Self(FormatConfig {
4747
indent_level: 0,
4848
indent: " ",
4949
no_comments: false,
@@ -122,7 +122,7 @@ pub(crate) fn autoformat_leading(leading: &mut String, config: &FormatConfig<'_>
122122
for _ in 0..config.indent_level {
123123
result.push_str(config.indent);
124124
}
125-
writeln!(result, "{}", trimmed).unwrap();
125+
writeln!(result, "{trimmed}").unwrap();
126126
}
127127
}
128128
}

src/identifier.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl KdlIdentifier {
6868

6969
/// Length of this identifier when rendered as a string.
7070
pub fn len(&self) -> usize {
71-
format!("{}", self).len()
71+
format!("{self}").len()
7272
}
7373

7474
/// Returns true if this identifier is completely empty.
@@ -117,7 +117,7 @@ impl KdlIdentifier {
117117
#[cfg(feature = "v1")]
118118
impl From<kdlv1::KdlIdentifier> for KdlIdentifier {
119119
fn from(value: kdlv1::KdlIdentifier) -> Self {
120-
KdlIdentifier {
120+
Self {
121121
value: value.value().into(),
122122
repr: value.repr().map(|x| x.into()),
123123
#[cfg(feature = "span")]
@@ -129,7 +129,7 @@ impl From<kdlv1::KdlIdentifier> for KdlIdentifier {
129129
impl Display for KdlIdentifier {
130130
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
131131
if let Some(repr) = &self.repr {
132-
write!(f, "{}", repr)
132+
write!(f, "{repr}")
133133
} else {
134134
write!(f, "{}", KdlValue::String(self.value().into()))
135135
}
@@ -138,7 +138,7 @@ impl Display for KdlIdentifier {
138138

139139
impl From<&str> for KdlIdentifier {
140140
fn from(value: &str) -> Self {
141-
KdlIdentifier {
141+
Self {
142142
value: value.to_string(),
143143
repr: None,
144144
#[cfg(feature = "span")]
@@ -149,7 +149,7 @@ impl From<&str> for KdlIdentifier {
149149

150150
impl From<String> for KdlIdentifier {
151151
fn from(value: String) -> Self {
152-
KdlIdentifier {
152+
Self {
153153
value,
154154
repr: None,
155155
#[cfg(feature = "span")]
@@ -168,7 +168,7 @@ impl FromStr for KdlIdentifier {
168168
type Err = KdlError;
169169

170170
fn from_str(s: &str) -> Result<Self, Self::Err> {
171-
KdlIdentifier::parse(s)
171+
Self::parse(s)
172172
}
173173
}
174174

src/node.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,7 @@ impl KdlNode {
625625
}
626626
}
627627
if idx > current_idx {
628-
panic!(
629-
"Insertion index (is {}) should be <= len (is {})",
630-
idx, current_idx
631-
);
628+
panic!("Insertion index (is {idx}) should be <= len (is {current_idx})");
632629
} else {
633630
self.entries.push(entry);
634631
None
@@ -720,8 +717,7 @@ impl KdlNode {
720717
}
721718
}
722719
panic!(
723-
"removal index (is {}) should be < number of index entries (is {})",
724-
idx, current_idx
720+
"removal index (is {idx}) should be < number of index entries (is {current_idx})"
725721
);
726722
}
727723
}
@@ -766,19 +762,19 @@ pub enum NodeKey {
766762

767763
impl From<&str> for NodeKey {
768764
fn from(key: &str) -> Self {
769-
NodeKey::Key(key.into())
765+
Self::Key(key.into())
770766
}
771767
}
772768

773769
impl From<String> for NodeKey {
774770
fn from(key: String) -> Self {
775-
NodeKey::Key(key.into())
771+
Self::Key(key.into())
776772
}
777773
}
778774

779775
impl From<usize> for NodeKey {
780776
fn from(key: usize) -> Self {
781-
NodeKey::Index(key)
777+
Self::Index(key)
782778
}
783779
}
784780

@@ -834,20 +830,20 @@ impl KdlNode {
834830
indent: usize,
835831
) -> std::fmt::Result {
836832
if let Some(KdlNodeFormat { leading, .. }) = self.format() {
837-
write!(f, "{}", leading)?;
833+
write!(f, "{leading}")?;
838834
} else {
839835
write!(f, "{:indent$}", "", indent = indent)?;
840836
}
841837
if let Some(ty) = &self.ty {
842-
write!(f, "({})", ty)?;
838+
write!(f, "({ty})")?;
843839
}
844840
write!(f, "{}", self.name)?;
845841
let mut space_before_children = true;
846842
for entry in &self.entries {
847843
if entry.format().is_none() {
848844
write!(f, " ")?;
849845
}
850-
write!(f, "{}", entry)?;
846+
write!(f, "{entry}")?;
851847
space_before_children = entry.format().is_none();
852848
}
853849
if let Some(children) = &self.children {

src/v2_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<I: Stream> AddContext<I, KdlParseContext> for KdlParseError {
140140

141141
impl<'a> FromExternalError<Input<'a>, ParseIntError> for KdlParseError {
142142
fn from_external_error(_: &Input<'a>, _kind: ErrorKind, e: ParseIntError) -> Self {
143-
KdlParseError {
143+
Self {
144144
span: None,
145145
message: Some(format!("{e}")),
146146
label: Some("invalid integer".into()),
@@ -152,7 +152,7 @@ impl<'a> FromExternalError<Input<'a>, ParseIntError> for KdlParseError {
152152

153153
impl<'a> FromExternalError<Input<'a>, ParseFloatError> for KdlParseError {
154154
fn from_external_error(_input: &Input<'a>, _kind: ErrorKind, e: ParseFloatError) -> Self {
155-
KdlParseError {
155+
Self {
156156
span: None,
157157
label: Some("invalid float".into()),
158158
help: None,
@@ -170,7 +170,7 @@ impl<'a> FromExternalError<Input<'a>, NegativeUnsignedError> for KdlParseError {
170170
_kind: ErrorKind,
171171
_e: NegativeUnsignedError,
172172
) -> Self {
173-
KdlParseError {
173+
Self {
174174
span: None,
175175
message: Some("Tried to parse a negative number as an unsigned integer".into()),
176176
label: Some("negative unsigned int".into()),

0 commit comments

Comments
 (0)