@@ -5,7 +5,6 @@ use core::ops::{
5
5
ShrAssign , Sub , SubAssign ,
6
6
} ;
7
7
use core:: str:: FromStr ;
8
- use serde:: { de, ser, Deserialize , Deserializer , Serialize } ;
9
8
10
9
use crate :: errors:: { DivideByZeroError , DivisionError , OverflowError , OverflowOperation , StdError } ;
11
10
use crate :: forward_ref:: { forward_ref_binop, forward_ref_op_assign} ;
@@ -19,6 +18,7 @@ use crate::{
19
18
use bnum:: types:: { I256 , U256 } ;
20
19
21
20
use super :: conversion:: { grow_be_int, try_from_int_to_int, try_from_uint_to_int} ;
21
+ use super :: impl_int_serde;
22
22
use super :: num_consts:: NumConsts ;
23
23
24
24
/// An implementation of i256 that is using strings for JSON encoding/decoding,
@@ -44,6 +44,7 @@ use super::num_consts::NumConsts;
44
44
#[ derive( Copy , Clone , Default , Debug , PartialEq , Eq , PartialOrd , Ord , schemars:: JsonSchema ) ]
45
45
pub struct Int256 ( #[ schemars( with = "String" ) ] pub ( crate ) I256 ) ;
46
46
47
+ impl_int_serde ! ( Int256 ) ;
47
48
forward_ref_partial_eq ! ( Int256 , Int256 ) ;
48
49
49
50
impl Int256 {
@@ -612,43 +613,6 @@ impl ShlAssign<u32> for Int256 {
612
613
}
613
614
forward_ref_op_assign ! ( impl ShlAssign , shl_assign for Int256 , u32 ) ;
614
615
615
- impl Serialize for Int256 {
616
- /// Serializes as an integer string using base 10
617
- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
618
- where
619
- S : ser:: Serializer ,
620
- {
621
- serializer. serialize_str ( & self . to_string ( ) )
622
- }
623
- }
624
-
625
- impl < ' de > Deserialize < ' de > for Int256 {
626
- /// Deserialized from an integer string using base 10
627
- fn deserialize < D > ( deserializer : D ) -> Result < Int256 , D :: Error >
628
- where
629
- D : Deserializer < ' de > ,
630
- {
631
- deserializer. deserialize_str ( Int256Visitor )
632
- }
633
- }
634
-
635
- struct Int256Visitor ;
636
-
637
- impl < ' de > de:: Visitor < ' de > for Int256Visitor {
638
- type Value = Int256 ;
639
-
640
- fn expecting ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
641
- formatter. write_str ( "string-encoded integer" )
642
- }
643
-
644
- fn visit_str < E > ( self , v : & str ) -> Result < Self :: Value , E >
645
- where
646
- E : de:: Error ,
647
- {
648
- Int256 :: try_from ( v) . map_err ( |e| E :: custom ( format_args ! ( "invalid Int256 '{v}' - {e}" ) ) )
649
- }
650
- }
651
-
652
616
impl < A > core:: iter:: Sum < A > for Int256
653
617
where
654
618
Self : Add < A , Output = Self > ,
0 commit comments