1
1
//! Copy data types
2
2
use crate :: { codec:: Fixed , datatypes:: Sv2DataType , Error } ;
3
- use core:: convert:: { TryFrom , TryInto } ;
4
3
5
- # [ cfg ( not ( feature = "no_std" ) ) ]
6
- use std :: io :: { Error as E , Read , Write } ;
4
+ use alloc :: vec :: Vec ;
5
+ use core :: convert :: { TryFrom , TryInto } ;
7
6
8
7
// Impl bool as a primitive
9
8
@@ -44,8 +43,8 @@ impl<'a> Sv2DataType<'a> for bool {
44
43
Self :: from_bytes_unchecked ( & mut data)
45
44
}
46
45
47
- #[ cfg( not ( feature = "no_std" ) ) ]
48
- fn from_reader_ ( reader : & mut impl Read ) -> Result < Self , Error > {
46
+ #[ cfg( feature = "std" ) ]
47
+ fn from_reader_ ( reader : & mut impl std :: io :: Read ) -> Result < Self , Error > {
49
48
let mut dst = [ 0_u8 ; Self :: SIZE ] ;
50
49
reader. read_exact ( & mut dst) ?;
51
50
Self :: from_bytes_ ( & mut dst)
@@ -58,8 +57,8 @@ impl<'a> Sv2DataType<'a> for bool {
58
57
} ;
59
58
}
60
59
61
- #[ cfg( not ( feature = "no_std" ) ) ]
62
- fn to_writer_ ( & self , writer : & mut impl Write ) -> Result < ( ) , E > {
60
+ #[ cfg( feature = "std" ) ]
61
+ fn to_writer_ ( & self , writer : & mut impl std :: io :: Write ) -> Result < ( ) , std :: io :: Error > {
63
62
match self {
64
63
true => writer. write_all ( & [ 1 ] ) ,
65
64
false => writer. write_all ( & [ 0 ] ) ,
@@ -104,8 +103,8 @@ macro_rules! impl_sv2_for_unsigned {
104
103
Self :: from_bytes_unchecked( & mut data)
105
104
}
106
105
107
- #[ cfg( not ( feature = "no_std" ) ) ]
108
- fn from_reader_( reader: & mut impl Read ) -> Result <Self , Error > {
106
+ #[ cfg( feature = "std" ) ]
107
+ fn from_reader_( reader: & mut impl std :: io :: Read ) -> Result <Self , Error > {
109
108
let mut dst = [ 0_u8 ; Self :: SIZE ] ;
110
109
reader. read_exact( & mut dst) ?;
111
110
Ok ( Self :: from_bytes_unchecked( & mut dst) )
@@ -117,8 +116,8 @@ macro_rules! impl_sv2_for_unsigned {
117
116
dst. copy_from_slice( & src) ;
118
117
}
119
118
120
- #[ cfg( not ( feature = "no_std" ) ) ]
121
- fn to_writer_( & self , writer: & mut impl Write ) -> Result <( ) , E > {
119
+ #[ cfg( feature = "std" ) ]
120
+ fn to_writer_( & self , writer: & mut impl std :: io :: Write ) -> Result <( ) , std :: io :: Error > {
122
121
let bytes = self . to_le_bytes( ) ;
123
122
writer. write_all( & bytes)
124
123
}
0 commit comments