Skip to content

Commit

Permalink
Clippy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wkennedy committed Nov 14, 2023
1 parent 37a74c8 commit 1638ec1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
8 changes: 3 additions & 5 deletions borsh-serde-adapter/src/deserialize_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ fn deserialize_to_serde_json(buffer: &mut &[u8], schema: &BorshSchemaContainer,
Ok(value)
}

//TODO cleanup
Definition::Sequence { length_width, length_range, elements } => {
let length_width = *length_width as u32;
let mut length = 0;
if length_width == 0 {
length = *length_range.end() as usize
let length = if length_width == 0 {
*length_range.end() as usize
} else {
length = u32::deserialize(buffer)? as usize;
u32::deserialize(buffer)? as usize
};

let mut values = Vec::<serde_json::Value>::with_capacity(length);
Expand Down
2 changes: 1 addition & 1 deletion borsh-serde-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
//! This library is still in early development and there are some caveats to be aware of. The use of u128 and i128 are
//! somewhat supported. In the case of deserialization u128/i128 are deserialized as strings, but serialization is not
//! supported.
pub mod deserialize_adapter;
pub mod serialize_adapter;
pub mod errors;
Expand Down
13 changes: 5 additions & 8 deletions borsh-serde-adapter/src/serialize_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_find_map)]

use std::io::{Write};
use std::str::FromStr;

Expand Down Expand Up @@ -86,16 +88,11 @@ fn serialize_serde_json_by_declaration_with_schema(
Ok(())
}

//TODO cleanup
Definition::Sequence { length_width, length_range, elements } => {
Definition::Sequence { length_width, length_range: _, elements } => {
let sequence = value.as_array().ok_or(ExpectationError::Array)?;
let length_width = *length_width as u32;
let mut length = 0;
if length_width == 0 {
length = *length_range.end() as usize
} else {
//Only serialize length for dynamically sized sequence (vec)
length = sequence.len();
if length_width != 0 {
let length = sequence.len();
BorshSerialize::serialize(&(length as u32), writer)?;
};
for item in sequence {
Expand Down

0 comments on commit 1638ec1

Please sign in to comment.