Skip to content

Commit

Permalink
Updated rustfmt settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Jan 31, 2023
1 parent b595434 commit 7fcbe19
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 86 deletions.
8 changes: 4 additions & 4 deletions pot/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::fmt::Display;

use chrono::{DateTime, Utc};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use fake::{
faker::{filesystem::en::FilePath, internet::en::Username, lorem::en::Sentence},
Fake,
};
use fake::faker::filesystem::en::FilePath;
use fake::faker::internet::en::Username;
use fake::faker::lorem::en::Sentence;
use fake::Fake;
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};

Expand Down
8 changes: 4 additions & 4 deletions pot/examples/logs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bincode::Options;
use chrono::{DateTime, Utc};
use cli_table::{Cell, Table};
use fake::{
faker::{filesystem::en::FilePath, internet::en::Username, lorem::en::Sentence},
Fake,
};
use fake::faker::filesystem::en::FilePath;
use fake::faker::internet::en::Username;
use fake::faker::lorem::en::Sentence;
use fake::Fake;
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use thousands::Separable;
Expand Down
13 changes: 8 additions & 5 deletions pot/src/de.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{borrow::Cow, collections::VecDeque, fmt::Debug};
use std::borrow::Cow;
use std::collections::VecDeque;
use std::fmt::Debug;

use byteorder::ReadBytesExt;
use derive_where::derive_where;
Expand All @@ -9,11 +11,11 @@ use serde::de::{
#[cfg(feature = "tracing")]
use tracing::instrument;

use crate::{
format::{self, Atom, Float, InnerFloat, InnerInteger, Integer, Nucleus, CURRENT_VERSION},
reader::{IoReader, Reader, SliceReader},
Error, Result,
use crate::format::{
self, Atom, Float, InnerFloat, InnerInteger, Integer, Nucleus, CURRENT_VERSION,
};
use crate::reader::{IoReader, Reader, SliceReader};
use crate::{Error, Result};

/// Deserializer for the Pot format.
#[derive_where(Debug)]
Expand Down Expand Up @@ -274,6 +276,7 @@ impl<'a, 'de, 's, R: Reader<'de>> de::Deserializer<'de> for &'a mut Deserializer
other => Err(Error::custom(format!("expected i8, got {other:?}"))),
}
}

#[cfg_attr(feature = "tracing", instrument(skip(visitor)))]
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value>
where
Expand Down
4 changes: 3 additions & 1 deletion pot/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{fmt::Display, str::Utf8Error, string::FromUtf8Error};
use std::fmt::Display;
use std::str::Utf8Error;
use std::string::FromUtf8Error;

use serde::{de, ser};

Expand Down
10 changes: 7 additions & 3 deletions pot/src/format.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::{borrow::Cow, fmt::Display};
use std::borrow::Cow;
use std::fmt::Display;

use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
use half::f16;
use serde::{de::Error as _, Deserialize, Serialize};
use serde::de::Error as _;
use serde::{Deserialize, Serialize};

pub(crate) const CURRENT_VERSION: u8 = 0;

use crate::{reader::Reader, Error};
use crate::reader::Reader;
use crate::Error;

/// Writes an atom header into `writer`.
#[allow(clippy::cast_possible_truncation)]
Expand Down Expand Up @@ -504,6 +507,7 @@ impl Integer {
InnerInteger::U128(value) => *value == 0,
}
}

/// Returns the contained value as an i8, or an error if the value is unable to fit.
// clippy::checked_conversions: try_from isn't const, and it would demote this from a const fn.
#[allow(clippy::cast_possible_wrap)]
Expand Down
21 changes: 10 additions & 11 deletions pot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ use std::io::Read;

use byteorder::WriteBytesExt;

pub use self::{
error::Error,
value::{OwnedValue, Value, ValueError},
};
pub use self::error::Error;
pub use self::value::{OwnedValue, Value, ValueError};
/// A result alias that returns [`Error`].
pub type Result<T> = std::result::Result<T, Error>;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

use crate::reader::IoReader;

Expand Down Expand Up @@ -175,16 +174,16 @@ impl Config {

#[cfg(test)]
mod tests {
use std::{borrow::Cow, marker::PhantomData};
use std::borrow::Cow;
use std::marker::PhantomData;

use serde::{Deserializer, Serializer};
use serde_json::{value::Value as JsonValue, Number};
use serde_json::value::Value as JsonValue;
use serde_json::Number;

use super::*;
use crate::{
format::{Float, Integer, CURRENT_VERSION},
value::Value,
};
use crate::format::{Float, Integer, CURRENT_VERSION};
use crate::value::Value;

fn init_tracing() {
drop(
Expand Down
5 changes: 4 additions & 1 deletion pot/src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{borrow::Cow, fmt::Debug, io::Read};
use std::borrow::Cow;
use std::fmt::Debug;
use std::io::Read;

use byteorder::ReadBytesExt;

Expand Down Expand Up @@ -54,6 +56,7 @@ impl<'a> Read for SliceReader<'a> {
self.data = remaining;
Ok(to_copy.len())
}

fn read_exact(&mut self, buf: &mut [u8]) -> std::io::Result<()> {
self.read(buf).map(|_| ())
}
Expand Down
37 changes: 16 additions & 21 deletions pot/src/ser.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use std::{
fmt::Debug,
ops::{Deref, DerefMut},
usize,
};
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};
use std::usize;

use byteorder::WriteBytesExt;
use derive_where::derive_where;
use serde::{ser, Serialize};
#[cfg(feature = "tracing")]
use tracing::instrument;

use crate::{
format::{self, Kind, Special, CURRENT_VERSION},
Error, Result,
};
use crate::format::{self, Kind, Special, CURRENT_VERSION};
use crate::{Error, Result};

/// A Pot serializer.
#[derive_where(Debug)]
Expand Down Expand Up @@ -62,16 +58,15 @@ impl<'a, W: WriteBytesExt> Serializer<'a, W> {
}

impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::Serializer for &'de mut Serializer<'a, W> {
type Ok = ();
type Error = Error;

type Ok = ();
type SerializeMap = MapSerializer<'de, 'a, W>;
type SerializeSeq = Self;
type SerializeStruct = MapSerializer<'de, 'a, W>;
type SerializeStructVariant = MapSerializer<'de, 'a, W>;
type SerializeTuple = Self;
type SerializeTupleStruct = Self;
type SerializeTupleVariant = Self;
type SerializeMap = MapSerializer<'de, 'a, W>;
type SerializeStruct = MapSerializer<'de, 'a, W>;
type SerializeStructVariant = MapSerializer<'de, 'a, W>;

fn is_human_readable(&self) -> bool {
false
Expand Down Expand Up @@ -308,8 +303,8 @@ impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::Serializer for &'de mut Serialize
}

impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeSeq for &'de mut Serializer<'a, W> {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
Expand All @@ -324,8 +319,8 @@ impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeSeq for &'de mut Seriali
}

impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeTuple for &'de mut Serializer<'a, W> {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
Expand All @@ -340,8 +335,8 @@ impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeTuple for &'de mut Seria
}

impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeTupleStruct for &'de mut Serializer<'a, W> {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
Expand All @@ -358,8 +353,8 @@ impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeTupleStruct for &'de mut
impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeTupleVariant
for &'de mut Serializer<'a, W>
{
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
Expand All @@ -380,8 +375,8 @@ pub struct MapSerializer<'de, 'a, W: WriteBytesExt> {
}

impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeMap for MapSerializer<'de, 'a, W> {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_key<T>(&mut self, key: &T) -> Result<()>
where
Expand All @@ -406,8 +401,8 @@ impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeMap for MapSerializer<'d
}

impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeStruct for MapSerializer<'de, 'a, W> {
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
where
Expand All @@ -428,8 +423,8 @@ impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeStruct for MapSerializer
impl<'de, 'a: 'de, W: WriteBytesExt + 'a> ser::SerializeStructVariant
for MapSerializer<'de, 'a, W>
{
type Ok = ();
type Error = Error;
type Ok = ();

fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
where
Expand Down
Loading

0 comments on commit 7fcbe19

Please sign in to comment.