diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs index 45389b73a4..1ec7037f7a 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/decodable.rs @@ -6,7 +6,7 @@ use crate::{ Error, }; use alloc::vec::Vec; -use std::convert::TryFrom; +use core::convert::TryFrom; #[cfg(not(feature = "no_std"))] use std::io::{Cursor, Read}; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs index fd626bc8fe..a26ae8e72f 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs @@ -11,6 +11,8 @@ mod impls; #[cfg(feature = "with_buffer_pool")] use buffer_sv2::Slice; +use alloc::vec::Vec; + /// Return the encoded byte size or a `Decodable` pub trait SizeHint { fn size_hint(data: &[u8], offset: usize) -> Result; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs index be6edeadc8..690f719fd9 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/copy_data_types.rs @@ -1,5 +1,7 @@ //! Copy data types use crate::{codec::Fixed, datatypes::Sv2DataType, Error}; + +use alloc::vec::Vec; use core::convert::{TryFrom, TryInto}; #[cfg(not(feature = "no_std"))] diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs index ad1bce76c3..8ab1bc9249 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/mod.rs @@ -12,11 +12,11 @@ pub use non_copy_data_types::{ B0255, B032, B064K, U256, }; +use alloc::vec::Vec; +use core::convert::TryInto; #[cfg(not(feature = "no_std"))] use std::io::{Error as E, Read, Write}; -use std::convert::TryInto; - pub trait Sv2DataType<'a>: Sized + SizeHint + GetSize + TryInto { fn from_bytes_(data: &'a mut [u8]) -> Result { Self::size_hint(data, 0)?; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs index 1703c5d2ea..e0f30bf38a 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/inner.rs @@ -4,9 +4,9 @@ use crate::{ datatypes::Sv2DataType, Error, }; -use core::convert::TryFrom; -use std::convert::TryInto; +use alloc::vec::Vec; +use core::convert::{TryFrom, TryInto}; #[cfg(not(feature = "no_std"))] use std::io::{Error as E, Read, Write}; diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs index 9a117786e2..40c47a7ba4 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs @@ -1,6 +1,10 @@ #[cfg(feature = "prop_test")] use quickcheck::{Arbitrary, Gen}; +use alloc::string::String; +#[cfg(feature = "prop_test")] +use alloc::vec::Vec; + mod inner; mod seq_inner; @@ -28,7 +32,6 @@ impl<'decoder> From<[u8; 32]> for U256<'decoder> { } } -#[cfg(not(feature = "with_serde"))] #[cfg(feature = "prop_test")] impl<'a> U256<'a> { pub fn from_gen(g: &mut Gen) -> Self { @@ -40,7 +43,6 @@ impl<'a> U256<'a> { } } -#[cfg(not(feature = "with_serde"))] #[cfg(feature = "prop_test")] impl<'a> B016M<'a> { pub fn from_gen(g: &mut Gen) -> Self { diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs index acc50f15f4..9da799ba92 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/seq_inner.rs @@ -280,7 +280,7 @@ impl_into_encodable_field_for_seq!(B064K<'a>); impl_into_encodable_field_for_seq!(B016M<'a>); #[cfg(feature = "prop_test")] -impl<'a, T> std::convert::TryFrom> for Vec { +impl<'a, T> core::convert::TryFrom> for Vec { type Error = &'static str; fn try_from(v: Seq0255<'a, T>) -> Result { if v.0.len() > 255 { @@ -292,7 +292,7 @@ impl<'a, T> std::convert::TryFrom> for Vec { } #[cfg(feature = "prop_test")] -impl<'a, T> std::convert::TryFrom> for Vec { +impl<'a, T> core::convert::TryFrom> for Vec { type Error = &'static str; fn try_from(v: Seq064K<'a, T>) -> Result { if v.0.len() > 64 { diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs index 929fb07a0e..f10a98a05e 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/lib.rs @@ -19,6 +19,9 @@ //! Seq0255 <-> SEQ0_255[T] //! Seq064K <-> SEQ0_64K[T] //! ``` + +#![cfg_attr(feature = "no_std", no_std)] + #[cfg(not(feature = "no_std"))] use std::io::{Error as E, ErrorKind}; @@ -35,6 +38,8 @@ pub use crate::codec::{ Fixed, GetSize, SizeHint, }; +use alloc::vec::Vec; + #[allow(clippy::wrong_self_convention)] pub fn to_bytes(src: T) -> Result, Error> { let mut result = vec![0_u8; src.get_size()]; @@ -279,7 +284,7 @@ impl From<&[u8]> for CVec { // Get the length, first, then the pointer (doing it the other way around **currently** doesn't cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec { data: ptr, @@ -295,7 +300,7 @@ impl From<&[u8]> for CVec { /// #[no_mangle] pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { - let input = std::slice::from_raw_parts(data, len); + let input = core::slice::from_raw_parts(data, len); let mut buffer: Vec = vec![0; len]; buffer.copy_from_slice(input); @@ -303,7 +308,7 @@ pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { // Get the length, first, then the pointer (doing it the other way around **currently** doesn't cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec { data: ptr, @@ -356,7 +361,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> let len = inner.len(); let cap = inner.capacity(); let ptr = inner.as_mut_ptr(); - std::mem::forget(inner); + core::mem::forget(inner); (ptr, len, cap) } @@ -365,7 +370,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> let len = inner.len(); let cap = inner.capacity(); let ptr = inner.as_mut_ptr(); - std::mem::forget(inner); + core::mem::forget(inner); (ptr, len, cap) } @@ -387,7 +392,7 @@ pub unsafe extern "C" fn init_cvec2() -> CVec2 { // Get the length, first, then the pointer (doing it the other way around **currently** doesn't cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); CVec2 { data: ptr, @@ -407,7 +412,7 @@ pub unsafe extern "C" fn cvec2_push(cvec2: &mut CVec2, cvec: CVec) { let len = buffer.len(); let ptr = buffer.as_mut_ptr(); - std::mem::forget(buffer); + core::mem::forget(buffer); cvec2.data = ptr; cvec2.len = len; @@ -421,7 +426,7 @@ impl<'a, T: Into> From> for CVec2 { let len = v.len(); let capacity = v.capacity(); let data = v.as_mut_ptr(); - std::mem::forget(v); + core::mem::forget(v); Self { data, len, @@ -436,7 +441,7 @@ impl<'a, T: Into> From> for CVec2 { let len = v.len(); let capacity = v.capacity(); let data = v.as_mut_ptr(); - std::mem::forget(v); + core::mem::forget(v); Self { data, len,