Skip to content

Commit

Permalink
Fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil committed Aug 7, 2024
1 parent 5d15c0c commit c4901e8
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions bindings/python/src/utils/serde_pyo3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where
max_depth,
max_elements,
num_elements: vec![0; max_depth],
max_string
max_string,
};
value.serialize(&mut serializer)?;
Ok(serializer.output)
Expand All @@ -51,7 +51,7 @@ where
max_depth,
max_elements: 100,
num_elements: vec![0; max_depth],
max_string
max_string,
};
value.serialize(&mut serializer)?;
Ok(serializer.output)
Expand Down Expand Up @@ -149,10 +149,10 @@ impl<'a> ser::Serializer for &'a mut Serializer {
// contains a '"' character.
fn serialize_str(self, v: &str) -> Result<()> {
self.output += "\"";
if v.len() > self.max_string{
if v.len() > self.max_string {
self.output += &v[..self.max_string];
self.output += "...";
}else{
} else {
self.output += v;
}
self.output += "\"";
Expand Down Expand Up @@ -261,7 +261,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
// support sequences for which the length is known up front.
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq> {
self.output += "[";
self.level = std::cmp::min(self.max_depth- 1, self.level + 1);
self.level = std::cmp::min(self.max_depth - 1, self.level + 1);
self.num_elements[self.level] = 0;
Ok(self)
}
Expand All @@ -272,7 +272,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
// length without needing to look at the serialized data.
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple> {
self.output += "(";
self.level = std::cmp::min(self.max_depth- 1, self.level + 1);
self.level = std::cmp::min(self.max_depth - 1, self.level + 1);
self.num_elements[self.level] = 0;
Ok(self)
}
Expand All @@ -298,15 +298,15 @@ impl<'a> ser::Serializer for &'a mut Serializer {
// variant.serialize(&mut *self)?;
self.output += variant;
self.output += "(";
self.level = std::cmp::min(self.max_depth- 1, self.level + 1);
self.level = std::cmp::min(self.max_depth - 1, self.level + 1);
self.num_elements[self.level] = 0;
Ok(self)
}

// Maps are represented in JSON as `{ K: V, K: V, ... }`.
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap> {
self.output += "{";
self.level = std::cmp::min(self.max_depth- 1, self.level + 1);
self.level = std::cmp::min(self.max_depth - 1, self.level + 1);
self.num_elements[self.level] = 0;
Ok(self)
}
Expand All @@ -325,7 +325,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
self.output += name
}
self.output += "(";
self.level = std::cmp::min(self.max_depth- 1, self.level + 1);
self.level = std::cmp::min(self.max_depth - 1, self.level + 1);
self.num_elements[self.level] = 0;
Ok(self)
}
Expand All @@ -342,7 +342,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
// variant.serialize(&mut *self)?;
self.output += variant;
self.output += "(";
self.level = std::cmp::min(self.max_depth- 1, self.level + 1);
self.level = std::cmp::min(self.max_depth - 1, self.level + 1);
self.num_elements[self.level] = 0;
Ok(self)
}
Expand All @@ -368,13 +368,13 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
{
self.num_elements[self.level] += 1;
let num_elements = self.num_elements[self.level];
if num_elements < self.max_elements{
if num_elements < self.max_elements {
if !self.output.ends_with('[') {
self.output += ", ";
}
value.serialize(&mut **self)
}else{
if num_elements == self.max_elements{
} else {
if num_elements == self.max_elements {
self.output += ", ...";
}
Ok(())
Expand All @@ -401,13 +401,13 @@ impl<'a> ser::SerializeTuple for &'a mut Serializer {
{
self.num_elements[self.level] += 1;
let num_elements = self.num_elements[self.level];
if num_elements < self.max_elements{
if num_elements < self.max_elements {
if !self.output.ends_with('(') {
self.output += ", ";
}
value.serialize(&mut **self)
}else{
if num_elements == self.max_elements{
} else {
if num_elements == self.max_elements {
self.output += ", ...";
}
Ok(())
Expand All @@ -433,13 +433,13 @@ impl<'a> ser::SerializeTupleStruct for &'a mut Serializer {
{
self.num_elements[self.level] += 1;
let num_elements = self.num_elements[self.level];
if num_elements < self.max_elements{
if num_elements < self.max_elements {
if !self.output.ends_with('(') {
self.output += ", ";
}
value.serialize(&mut **self)
}else{
if num_elements == self.max_elements{
} else {
if num_elements == self.max_elements {
self.output += ", ...";
}
Ok(())
Expand Down Expand Up @@ -473,13 +473,13 @@ impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
{
self.num_elements[self.level] += 1;
let num_elements = self.num_elements[self.level];
if num_elements < self.max_elements{
if num_elements < self.max_elements {
if !self.output.ends_with('(') {
self.output += ", ";
}
value.serialize(&mut **self)
}else{
if num_elements == self.max_elements{
} else {
if num_elements == self.max_elements {
self.output += ", ...";
}
Ok(())
Expand Down Expand Up @@ -520,13 +520,13 @@ impl<'a> ser::SerializeMap for &'a mut Serializer {
{
self.num_elements[self.level] += 1;
let num_elements = self.num_elements[self.level];
if num_elements < self.max_elements{
if num_elements < self.max_elements {
if !self.output.ends_with('{') {
self.output += ", ";
}
key.serialize(&mut **self)
}else{
if num_elements == self.max_elements{
} else {
if num_elements == self.max_elements {
self.output += ", ...";
}
Ok(())
Expand All @@ -541,10 +541,10 @@ impl<'a> ser::SerializeMap for &'a mut Serializer {
T: ?Sized + Serialize,
{
let num_elements = self.num_elements[self.level];
if num_elements < self.max_elements{
if num_elements < self.max_elements {
self.output += ":";
value.serialize(&mut **self)
}else{
} else {
Ok(())
}
}
Expand Down

0 comments on commit c4901e8

Please sign in to comment.