Skip to content

Commit

Permalink
apply revision
Browse files Browse the repository at this point in the history
  • Loading branch information
lorbax committed Jun 26, 2024
1 parent 3a2221d commit e38f853
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::{
};
use crate::primitives::{FixedSize, GetSize};
use alloc::vec::Vec;
use debug_assert;
use serde::{
ser::{self, SerializeSeq, SerializeTuple},
Deserialize, Deserializer, Serialize,
Expand Down Expand Up @@ -69,7 +70,7 @@ impl<'s, T: Clone + Serialize + TryFromBSlice<'s>> Serialize for Sv2Option<'s, T
}
(None, Some(data)) => {
if serializer.is_human_readable() {
let data_ = self.data.clone().unwrap();
let data_ = data.clone();
let mut seq = serializer.serialize_seq(Some(data_.len()))?;
for item in data_ {
seq.serialize_element(&item)?;
Expand All @@ -83,7 +84,13 @@ impl<'s, T: Clone + Serialize + TryFromBSlice<'s>> Serialize for Sv2Option<'s, T
seq.end()
}
}
_ => panic!(),
_ => {
debug_assert!(
false,
"sv2option can never have boh fields of the same type"
);
panic!()
}
}
}
}
Expand Down Expand Up @@ -231,22 +238,29 @@ impl<'a, T: Clone + FixedSize + Serialize + TryFromBSlice<'a>> GetSize for Sv2Op
}
impl<'s> Sv2Option<'s, U256<'s>> {
pub fn into_static(self) -> Sv2Option<'static, U256<'static>> {
if let Some(inner) = self.data {
let inner = inner.clone();
let data = inner.into_iter().map(|i| i.into_static()).collect();
Sv2Option {
seq: None,
data: Some(data),
match (self.data, self.seq) {
(None, Some(seq)) => {
let data = seq.parse().unwrap();
let data = data.into_iter().map(|i| i.into_static()).collect();
Sv2Option {
seq: None,
data: Some(data),
}
}
} else {
// this is an already valid seq should be safe to call the unwraps.
// also this library shouldn't be used for priduction envs so is ok do thigs like this
// one
let data = self.seq.unwrap().parse().unwrap();
let data = data.into_iter().map(|i| i.into_static()).collect();
Sv2Option {
seq: None,
data: Some(data),
(Some(inner), None) => {
let inner = inner.clone();
let data = inner.into_iter().map(|i| i.into_static()).collect();
Sv2Option {
seq: None,
data: Some(data),
}
}
_ => {
debug_assert!(
false,
"sv2option can never have boh fields of the same type"
);
panic!()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'s, T: Clone + Serialize + TryFromBSlice<'s>> Serialize for Seq0255<'s, T>
}
(None, Some(data)) => {
if serializer.is_human_readable() {
let data_ = self.data.clone().unwrap();
let data_ = data.clone();
let mut seq = serializer.serialize_seq(Some(data_.len()))?;
for item in data_ {
seq.serialize_element(&item)?;
Expand Down Expand Up @@ -235,22 +235,32 @@ impl<'a, T: Clone + FixedSize + Serialize + TryFromBSlice<'a>> GetSize for Seq02
}
impl<'s> Seq0255<'s, U256<'s>> {
pub fn into_static(self) -> Seq0255<'static, U256<'static>> {
if let Some(inner) = self.data {
let inner = inner.clone();
let data = inner.into_iter().map(|i| i.into_static()).collect();
Seq0255 {
seq: None,
data: Some(data),
match (self.data, self.seq) {
(None, Some(seq)) => {
// this is an already valid seq should be safe to call the unwraps.
// also this library shouldn't be used for priduction envs so is ok do thigs like this
// one
let data = seq.parse().unwrap();
let data = data.into_iter().map(|i| i.into_static()).collect();
Seq0255 {
seq: None,
data: Some(data),
}
}
} else {
// this is an already valid seq should be safe to call the unwraps.
// also this library shouldn't be used for priduction envs so is ok do thigs like this
// one
let data = self.seq.unwrap().parse().unwrap();
let data = data.into_iter().map(|i| i.into_static()).collect();
Seq0255 {
seq: None,
data: Some(data),
(Some(inner), None) => {
let inner = inner.clone();
let data = inner.into_iter().map(|i| i.into_static()).collect();
Seq0255 {
seq: None,
data: Some(data),
}
}
_ => {
debug_assert!(
false,
"sv2option can never have boh fields of the same type"
);
panic!()
}
}
}
Expand Down

0 comments on commit e38f853

Please sign in to comment.