Skip to content

Commit

Permalink
run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Feb 2, 2020
1 parent add85c9 commit 72a1805
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 41 deletions.
8 changes: 3 additions & 5 deletions json/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ use miniserde::Serialize as MiniSerialize;
#[test]
fn sval_json_writer_is_valid() {
sval::test::stream_exhaustive(
|| {
sval_json::Writer::new(Vec::new())
},
|| sval_json::Writer::new(Vec::new()),
|writer| match writer {
// If the result is ok then the writer should be valid
Ok(writer) => {
writer.end().unwrap();
},
}
// If the result is not ok then the error should be unsupported
// This will happen with non-string keys
Err(e) => assert!(e.is_unsupported()),
}
},
);
}

Expand Down
18 changes: 14 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ impl Error {
/** Declare some structure as unsupported. */
#[inline]
pub fn unsupported(operation: &'static str) -> Self {
Error(ErrorInner::Unsupported { msg: operation, default: false })
Error(ErrorInner::Unsupported {
msg: operation,
default: false,
})
}

/** Whether or not an error is because some operation was unsupported. */
Expand All @@ -39,7 +42,10 @@ impl Error {

#[allow(dead_code)]
pub(crate) fn default_unsupported(operation: &'static str) -> Self {
Error(ErrorInner::Unsupported { msg: operation, default: true })
Error(ErrorInner::Unsupported {
msg: operation,
default: true,
})
}

#[allow(dead_code)]
Expand Down Expand Up @@ -80,7 +86,9 @@ enum ErrorInner {
impl fmt::Debug for ErrorInner {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ErrorInner::Unsupported { msg: op, .. } => write!(f, "unsupported stream operation: {}", op),
ErrorInner::Unsupported { msg: op, .. } => {
write!(f, "unsupported stream operation: {}", op)
}
ErrorInner::Static(msg) => msg.fmt(f),
#[cfg(not(feature = "alloc"))]
ErrorInner::Custom(ref err) => err.fmt(f),
Expand All @@ -93,7 +101,9 @@ impl fmt::Debug for ErrorInner {
impl fmt::Display for ErrorInner {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ErrorInner::Unsupported { msg: op, .. } => write!(f, "unsupported stream operation: {}", op),
ErrorInner::Unsupported { msg: op, .. } => {
write!(f, "unsupported stream operation: {}", op)
}
ErrorInner::Static(msg) => msg.fmt(f),
#[cfg(not(feature = "alloc"))]
ErrorInner::Custom(ref err) => err.fmt(f),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ mod std {
pub use crate::alloc_lib::{
boxed,
collections,
vec,
string,
rc,
string,
vec,
};

pub use crate::core_lib::*;
Expand Down
2 changes: 1 addition & 1 deletion src/serde/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl fmt::Display for Error {
}
}

impl ser::StdError for Error { }
impl ser::StdError for Error {}

pub(super) fn err<E>(msg: &'static str) -> impl FnOnce(E) -> crate::Error
where
Expand Down
10 changes: 8 additions & 2 deletions src/serde/to_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,10 @@ mod alloc_support {
None => {
match self.take_current() {
Current::Serializer(ser) => {
let seq = ser.serialize_seq(len).map(Current::SerializeSeq).map_err(err("error serializing sequence"))?;
let seq = ser
.serialize_seq(len)
.map(Current::SerializeSeq)
.map_err(err("error serializing sequence"))?;
self.current = Some(seq);
}
current => {
Expand Down Expand Up @@ -558,7 +561,10 @@ mod alloc_support {
None => {
match self.take_current() {
Current::Serializer(ser) => {
let map = ser.serialize_map(len).map(Current::SerializeMap).map_err(err("error serializing map"))?;
let map = ser
.serialize_map(len)
.map(Current::SerializeMap)
.map_err(err("error serializing map"))?;
self.current = Some(map);
}
current => {
Expand Down
12 changes: 6 additions & 6 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ mod alloc_support {
string::String,
vec::Vec,
},
stream::{
self,
OwnedStream,
Stream,
},
value::{
owned::Kind,
OwnedValue,
Value,
},
stream::{
self,
Stream,
OwnedStream,
},
};

/**
Expand Down Expand Up @@ -166,7 +166,7 @@ mod alloc_support {
panic!("value `{:?}` is unsupported (a method on `Stream` hasn't been overriden)", tokens);
}
}

check(r);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/value/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ mod std_support {
use crate::std::{
collections::HashMap,
hash::{
Hash,
BuildHasher,
Hash,
},
sync::Arc,
};
Expand Down
4 changes: 3 additions & 1 deletion src/value/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ impl Primitive {
}

fn collect(v: impl Value) -> Option<Token> {
crate::stream(Primitive::new(), v).ok().and_then(|buf| buf.token)
crate::stream(Primitive::new(), v)
.ok()
.and_then(|buf| buf.token)
}

fn set(&mut self, kind: Kind, depth: stack::Depth) {
Expand Down
38 changes: 19 additions & 19 deletions tests/serde_no_alloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,57 @@ sval_if_alloc! {
Value,
},
};

#[derive(Value)]
struct Struct<'a> {
a: i32,
b: i32,
#[sval(rename = "renamed")]
c: Nested<'a>,
}

#[derive(Value)]
struct Nested<'a> {
a: i32,
b: &'a str,
}

struct Anonymous;

impl Value for Anonymous {
fn stream(&self, stream: &mut value::Stream) -> value::Result {
stream.map_begin(None)?;

stream.map_key_begin()?.i64(1)?;

stream.map_value_begin()?.map_begin(None)?;

stream.map_key(2)?;

stream.map_value_begin()?.seq_begin(None)?;

stream.seq_elem_begin()?.i64(3)?;

stream.seq_end()?;

stream.map_end()?;

stream.map_key(11)?;

stream.map_value(111)?;

stream.map_end()
}
}

#[test]
fn sval_derive() {
let ser = sval::serde::to_serialize(Struct {
a: 1,
b: 2,
c: Nested { a: 3, b: "Hello!" },
});

let v = sval::test::tokens(sval::serde::to_value(ser));
assert_eq!(
vec![
Expand All @@ -88,14 +88,14 @@ sval_if_alloc! {
v
);
}

#[test]
#[should_panic]
fn sval_to_serde_anonymous() {
let ser = sval::serde::to_serialize(Anonymous);

// The anonymous map isn't supported in no-std
sval::test::tokens(sval::serde::to_value(ser));
}
}
}
}

0 comments on commit 72a1805

Please sign in to comment.