Skip to content

Commit

Permalink
Fix Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kerristrasz committed Jun 26, 2024
1 parent e215265 commit cd5829b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/de.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Deserialize KeyValues text to Rust types.
// TODO: impl de; remove
#![allow(dead_code)]

use crate::Result;
use serde::de::DeserializeOwned;
use serde::Deserialize;
Expand Down Expand Up @@ -62,7 +65,7 @@ mod tests {
pub bar: String,
}

const SIMPLE_KEYVALUES: &'static str = indoc! {r##"
const SIMPLE_KEYVALUES: &str = indoc! {r##"
// This is a comment. It should not be parsed. This is verified by
// adding some bizzare comments.
Expand Down Expand Up @@ -101,7 +104,7 @@ mod tests {
assert_eq!(foo.bar, "baz");
}

const ANIMALS: &'static str = indoc! {r##"
const ANIMALS: &str = indoc! {r##"
"Cats" {
"Cat" {
"Name" "Archie"
Expand Down
1 change: 1 addition & 0 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub fn kv_to_writer_pretty<W: Write, T: ?Sized + Serialize, F: Formatter>(
#[cfg(test)]
mod tests {
use super::*;
#[cfg(feature = "preserve_order")]
use crate::{KeyValues, Object, Value};
use indoc::indoc;

Expand Down
2 changes: 1 addition & 1 deletion src/ser/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl PrettyFormatter {
if elem == ElementKind::Object {
self.indent_level -= 1;
}
return elem;
elem
}

fn write_indent<W: ?Sized + Write>(&mut self, writer: &mut W) -> io::Result<()> {
Expand Down
14 changes: 7 additions & 7 deletions src/ser/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ impl<W: Write, F: Formatter> Serializer<W, F> {
.and_then(|_| self.formatter.write_string(&mut self.writer, key))
.and_then(|_| self.formatter.end_key(&mut self.writer))
.and_then(|_| self.formatter.begin_value(&mut self.writer))
.map_err(|e| Error::Io(e))?;
.map_err(Error::Io)?;
}

self.formatter
.begin_object(&mut self.writer)
.map_err(|e| Error::Io(e))
.map_err(Error::Io)
}

fn end_map(&mut self) -> Result<()> {
self.formatter
.end_object(&mut self.writer)
.map_err(|e| Error::Io(e))?;
.map_err(Error::Io)?;

if !self.elements.is_empty() {
self.formatter
.end_value(&mut self.writer)
.map_err(|e| Error::Io(e))?;
.map_err(Error::Io)?;
}

Ok(())
Expand Down Expand Up @@ -88,16 +88,16 @@ impl<W: Write, F: Formatter> Serializer<W, F> {
.and_then(|_| self.formatter.begin_value(&mut self.writer))
.and_then(|_| self.formatter.write_string(&mut self.writer, value))
.and_then(|_| self.formatter.end_value(&mut self.writer))
.map_err(|e| Error::Io(e))
.map_err(Error::Io)
} else {
// We're at the root level. Just write the plain string.
self.formatter
.write_string(&mut self.writer, value)
.map_err(|e| Error::Io(e))
.map_err(Error::Io)
}
}

fn current_key<'a>(elements: &'a Vec<Option<Cow<'a, str>>>) -> Option<&'a str> {
fn current_key<'a>(elements: &'a [Option<Cow<'a, str>>]) -> Option<&'a str> {
elements.last().map(|element| match element {
Some(direct_key) => direct_key.as_ref(),
None => elements
Expand Down
5 changes: 4 additions & 1 deletion tests/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use vdflex::ser::{
kv_to_string, kv_to_string_pretty, to_string, to_string_pretty, BraceStyle, FormatOpts,
PrettyFormatter, Quoting,
};
use vdflex::{Error, KeyValues, Object, Result, Value};
use vdflex::{Error, Result};
#[cfg(feature = "preserve_order")]
use vdflex::{KeyValues, Object, Value};

#[derive(Serialize)]
struct UnitStruct;
Expand All @@ -25,6 +27,7 @@ struct Struct {
b: bool,
}

#[allow(clippy::enum_variant_names)]
#[derive(Serialize)]
enum Enum {
UnitVariant,
Expand Down

0 comments on commit cd5829b

Please sign in to comment.