Cargo fmt

This commit is contained in:
Alex 2022-12-15 15:38:10 +01:00
parent 52f6bd177c
commit 1579030b44
Signed by: lx
GPG key ID: 0E496D15096376BE
3 changed files with 60 additions and 62 deletions

View file

@ -378,7 +378,9 @@ impl<'a, 'b> Term<'a, 'b> {
/// ```
pub fn list(&self) -> Result<Vec<Term<'a, '_>>, TypeError> {
match self.0.mkref() {
AnyTerm::ListRef(_r, l) => Ok(l.iter().map(|x| Term(x.mkref().into())).collect::<Vec<_>>()),
AnyTerm::ListRef(_r, l) => {
Ok(l.iter().map(|x| Term(x.mkref().into())).collect::<Vec<_>>())
}
_ => Err(TypeError::WrongType("LIST")),
}
}

View file

@ -312,7 +312,10 @@ impl<'a> T<'a> {
buf.extend_from_slice(b"[]");
} else if l.len() == 1 {
buf.extend_from_slice(b"[ ");
l.into_iter().next().unwrap().encode_aux(buf, indent + 2, false);
l.into_iter()
.next()
.unwrap()
.encode_aux(buf, indent + 2, false);
buf.extend_from_slice(b" ]");
} else {
let indent2 = indent + 2;
@ -368,7 +371,7 @@ impl<'a> T<'a> {
}
T::List(l) => {
buf.push(b'[');
for (i,item) in l.into_iter().enumerate() {
for (i, item) in l.into_iter().enumerate() {
if i > 0 {
buf.push(b',');
}
@ -390,18 +393,15 @@ impl<'a> T<'a> {
#[cfg(test)]
mod tests {
use crate::debug;
use super::*;
use crate::debug;
#[test]
fn complex1() {
let input = seq([
string("HELLO").unwrap(),
string("alexhelloworld").unwrap(),
list([
string("dude").unwrap(),
string("why").unwrap(),
]),
list([string("dude").unwrap(), string("why").unwrap()]),
dict([
("from", string("jxx").unwrap()),
("subject", string("hello").unwrap()),
@ -427,10 +427,7 @@ mod tests {
let input = seq([
string("HELLO").unwrap(),
string("alexhelloworld").unwrap(),
list([
string("dude").unwrap(),
string("why").unwrap(),
]),
list([string("dude").unwrap(), string("why").unwrap()]),
dict([
("from", string("jxx").unwrap()),
("subject", string("hello").unwrap()),

View file

@ -11,9 +11,9 @@ pub use ser::{to_bytes, to_term, Serializer};
#[cfg(test)]
mod tests {
use super::*;
use crate::debug;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::debug;
fn test_bidir<T: Serialize + for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug>(
input: T,
@ -96,8 +96,7 @@ mod tests {
E::Struct { a: 1 },
E::Tuple(3, 2),
];
let expected =
r#"[E.Unit,E.Unit,E.Newtype 1,E.Tuple 1 2,E.Struct {a=1},E.Tuple 3 2]"#;
let expected = r#"[E.Unit,E.Unit,E.Newtype 1,E.Tuple 1 2,E.Struct {a=1},E.Tuple 3 2]"#;
test_bidir(input, expected);
}