Skip to content

ran clippy + cargo fmt #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl KdlDocument {

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

/// Returns true if this document is completely empty (including whitespace)
Expand Down Expand Up @@ -347,7 +347,7 @@ impl KdlDocument {
pub fn parse(s: &str) -> Result<Self, KdlError> {
#[cfg(not(feature = "v1-fallback"))]
{
KdlDocument::parse_v2(s)
Self::parse_v2(s)
}
#[cfg(feature = "v1-fallback")]
{
Expand Down Expand Up @@ -457,7 +457,7 @@ impl KdlDocument {
#[cfg(feature = "v1")]
impl From<kdlv1::KdlDocument> for KdlDocument {
fn from(value: kdlv1::KdlDocument) -> Self {
KdlDocument {
Self {
nodes: value.nodes().iter().map(|x| x.clone().into()).collect(),
format: Some(KdlDocumentFormat {
leading: value.leading().unwrap_or("").into(),
Expand Down Expand Up @@ -522,7 +522,7 @@ impl std::str::FromStr for KdlDocument {
type Err = KdlError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
KdlDocument::parse(s)
Self::parse(s)
}
}

Expand All @@ -539,13 +539,13 @@ impl KdlDocument {
indent: usize,
) -> std::fmt::Result {
if let Some(KdlDocumentFormat { leading, .. }) = self.format() {
write!(f, "{}", leading)?;
write!(f, "{leading}")?;
}
for node in &self.nodes {
node.stringify(f, indent)?;
}
if let Some(KdlDocumentFormat { trailing, .. }) = self.format() {
write!(f, "{}", trailing)?;
write!(f, "{trailing}")?;
}
Ok(())
}
Expand Down
30 changes: 15 additions & 15 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl std::hash::Hash for KdlEntry {
impl KdlEntry {
/// Creates a new Argument (positional) KdlEntry.
pub fn new(value: impl Into<KdlValue>) -> Self {
KdlEntry {
Self {
ty: None,
value: value.into(),
name: None,
Expand Down Expand Up @@ -129,7 +129,7 @@ impl KdlEntry {

/// Creates a new Property (key/value) KdlEntry.
pub fn new_prop(key: impl Into<KdlIdentifier>, value: impl Into<KdlValue>) -> Self {
KdlEntry {
Self {
ty: None,
value: value.into(),
name: Some(key.into()),
Expand All @@ -153,7 +153,7 @@ impl KdlEntry {

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

/// Returns true if this entry is completely empty (including whitespace).
Expand Down Expand Up @@ -385,7 +385,7 @@ impl KdlEntry {
#[cfg(feature = "v1")]
impl From<kdlv1::KdlEntry> for KdlEntry {
fn from(value: kdlv1::KdlEntry) -> Self {
KdlEntry {
Self {
ty: value.ty().map(|x| x.clone().into()),
value: value.value().clone().into(),
name: value.name().map(|x| x.clone().into()),
Expand All @@ -404,29 +404,29 @@ impl From<kdlv1::KdlEntry> for KdlEntry {
impl Display for KdlEntry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(KdlEntryFormat { leading, .. }) = &self.format {
write!(f, "{}", leading)?;
write!(f, "{leading}")?;
}
if let Some(name) = &self.name {
write!(f, "{}", name)?;
write!(f, "{name}")?;
if let Some(KdlEntryFormat {
after_key,
after_eq,
..
}) = &self.format
{
write!(f, "{}={}", after_key, after_eq)?;
write!(f, "{after_key}={after_eq}")?;
} else {
write!(f, "=")?;
}
}
if let Some(ty) = &self.ty {
write!(f, "(")?;
if let Some(KdlEntryFormat { before_ty_name, .. }) = &self.format {
write!(f, "{}", before_ty_name)?;
write!(f, "{before_ty_name}")?;
}
write!(f, "{}", ty)?;
write!(f, "{ty}")?;
if let Some(KdlEntryFormat { after_ty_name, .. }) = &self.format {
write!(f, "{}", after_ty_name)?;
write!(f, "{after_ty_name}")?;
}
write!(f, ")")?;
}
Expand All @@ -436,12 +436,12 @@ impl Display for KdlEntry {
..
}) = &self.format
{
write!(f, "{}{}", after_ty, value_repr)?;
write!(f, "{after_ty}{value_repr}")?;
} else {
write!(f, "{}", self.value)?;
}
if let Some(KdlEntryFormat { trailing, .. }) = &self.format {
write!(f, "{}", trailing)?;
write!(f, "{trailing}")?;
}
Ok(())
}
Expand All @@ -452,7 +452,7 @@ where
T: Into<KdlValue>,
{
fn from(value: T) -> Self {
KdlEntry::new(value)
Self::new(value)
}
}

Expand All @@ -462,15 +462,15 @@ where
V: Into<KdlValue>,
{
fn from((key, value): (K, V)) -> Self {
KdlEntry::new_prop(key, value)
Self::new_prop(key, value)
}
}

impl FromStr for KdlEntry {
type Err = KdlError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
KdlEntry::parse(s)
Self::parse(s)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Diagnostic for KdlDiagnostic {
impl From<kdlv1::KdlError> for KdlError {
fn from(value: kdlv1::KdlError) -> Self {
let input = Arc::new(value.input);
KdlError {
Self {
input: input.clone(),
diagnostics: vec![KdlDiagnostic {
input,
Expand Down
4 changes: 2 additions & 2 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct FormatConfigBuilder<'a>(FormatConfig<'a>);
impl<'a> FormatConfigBuilder<'a> {
/// Creates a new [`FormatConfig`] builder with default configuration.
pub const fn new() -> Self {
FormatConfigBuilder(FormatConfig {
Self(FormatConfig {
indent_level: 0,
indent: " ",
no_comments: false,
Expand Down Expand Up @@ -122,7 +122,7 @@ pub(crate) fn autoformat_leading(leading: &mut String, config: &FormatConfig<'_>
for _ in 0..config.indent_level {
result.push_str(config.indent);
}
writeln!(result, "{}", trimmed).unwrap();
writeln!(result, "{trimmed}").unwrap();
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl KdlIdentifier {

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

/// Returns true if this identifier is completely empty.
Expand Down Expand Up @@ -117,7 +117,7 @@ impl KdlIdentifier {
#[cfg(feature = "v1")]
impl From<kdlv1::KdlIdentifier> for KdlIdentifier {
fn from(value: kdlv1::KdlIdentifier) -> Self {
KdlIdentifier {
Self {
value: value.value().into(),
repr: value.repr().map(|x| x.into()),
#[cfg(feature = "span")]
Expand All @@ -129,7 +129,7 @@ impl From<kdlv1::KdlIdentifier> for KdlIdentifier {
impl Display for KdlIdentifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(repr) = &self.repr {
write!(f, "{}", repr)
write!(f, "{repr}")
} else {
write!(f, "{}", KdlValue::String(self.value().into()))
}
Expand All @@ -138,7 +138,7 @@ impl Display for KdlIdentifier {

impl From<&str> for KdlIdentifier {
fn from(value: &str) -> Self {
KdlIdentifier {
Self {
value: value.to_string(),
repr: None,
#[cfg(feature = "span")]
Expand All @@ -149,7 +149,7 @@ impl From<&str> for KdlIdentifier {

impl From<String> for KdlIdentifier {
fn from(value: String) -> Self {
KdlIdentifier {
Self {
value,
repr: None,
#[cfg(feature = "span")]
Expand All @@ -168,7 +168,7 @@ impl FromStr for KdlIdentifier {
type Err = KdlError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
KdlIdentifier::parse(s)
Self::parse(s)
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,7 @@ impl KdlNode {
}
}
if idx > current_idx {
panic!(
"Insertion index (is {}) should be <= len (is {})",
idx, current_idx
);
panic!("Insertion index (is {idx}) should be <= len (is {current_idx})");
} else {
self.entries.push(entry);
None
Expand Down Expand Up @@ -720,8 +717,7 @@ impl KdlNode {
}
}
panic!(
"removal index (is {}) should be < number of index entries (is {})",
idx, current_idx
"removal index (is {idx}) should be < number of index entries (is {current_idx})"
);
}
}
Expand Down Expand Up @@ -766,19 +762,19 @@ pub enum NodeKey {

impl From<&str> for NodeKey {
fn from(key: &str) -> Self {
NodeKey::Key(key.into())
Self::Key(key.into())
}
}

impl From<String> for NodeKey {
fn from(key: String) -> Self {
NodeKey::Key(key.into())
Self::Key(key.into())
}
}

impl From<usize> for NodeKey {
fn from(key: usize) -> Self {
NodeKey::Index(key)
Self::Index(key)
}
}

Expand Down Expand Up @@ -834,20 +830,20 @@ impl KdlNode {
indent: usize,
) -> std::fmt::Result {
if let Some(KdlNodeFormat { leading, .. }) = self.format() {
write!(f, "{}", leading)?;
write!(f, "{leading}")?;
} else {
write!(f, "{:indent$}", "", indent = indent)?;
}
if let Some(ty) = &self.ty {
write!(f, "({})", ty)?;
write!(f, "({ty})")?;
}
write!(f, "{}", self.name)?;
let mut space_before_children = true;
for entry in &self.entries {
if entry.format().is_none() {
write!(f, " ")?;
}
write!(f, "{}", entry)?;
write!(f, "{entry}")?;
space_before_children = entry.format().is_none();
}
if let Some(children) = &self.children {
Expand Down
6 changes: 3 additions & 3 deletions src/v2_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<I: Stream> AddContext<I, KdlParseContext> for KdlParseError {

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

impl<'a> FromExternalError<Input<'a>, ParseFloatError> for KdlParseError {
fn from_external_error(_input: &Input<'a>, _kind: ErrorKind, e: ParseFloatError) -> Self {
KdlParseError {
Self {
span: None,
label: Some("invalid float".into()),
help: None,
Expand All @@ -170,7 +170,7 @@ impl<'a> FromExternalError<Input<'a>, NegativeUnsignedError> for KdlParseError {
_kind: ErrorKind,
_e: NegativeUnsignedError,
) -> Self {
KdlParseError {
Self {
span: None,
message: Some("Tried to parse a negative number as an unsigned integer".into()),
label: Some("negative unsigned int".into()),
Expand Down
Loading