File tree 3 files changed +36
-3
lines changed
3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 41
41
42
42
pub const PUBKEY : & str = "7RoSF9fUmdphVCpabEoefH81WwrW7orsWonXWqTXkKV8" ;
43
43
44
- pub type Mocks = HashMap < RpcRequest , Value > ;
44
+ #[ derive( Default ) ]
45
+ pub struct Mocks ( Vec < ( RpcRequest , Value ) > ) ;
46
+
47
+ impl Mocks {
48
+ pub fn new ( ) -> Self {
49
+ Self ( Vec :: new ( ) )
50
+ }
51
+
52
+ pub fn from < const N : usize > ( mocks : [ ( RpcRequest , Value ) ; N ] ) -> Self {
53
+ Self ( mocks. to_vec ( ) )
54
+ }
55
+
56
+ pub fn insert ( & mut self , request : RpcRequest , response : Value ) {
57
+ self . 0 . push ( ( request, response) ) ;
58
+ }
59
+
60
+ pub fn remove ( & mut self , request : & RpcRequest ) -> Option < Value > {
61
+ self . 0
62
+ . iter ( )
63
+ . position ( |( r, _) | r == request)
64
+ . map ( |index| self . 0 . remove ( index) . 1 )
65
+ }
66
+ }
67
+
68
+ impl FromIterator < ( RpcRequest , Value ) > for Mocks {
69
+ fn from_iter < T : IntoIterator < Item = ( RpcRequest , Value ) > > ( iter : T ) -> Self {
70
+ let mut mocks = Mocks :: new ( ) ;
71
+ for ( request, response) in iter {
72
+ mocks. insert ( request, response) ;
73
+ }
74
+ mocks
75
+ }
76
+ }
77
+
45
78
pub struct MockSender {
46
79
mocks : RwLock < Mocks > ,
47
80
url : String ,
Original file line number Diff line number Diff line change @@ -4707,7 +4707,7 @@ pub(crate) fn parse_keyed_accounts(
4707
4707
4708
4708
#[ doc( hidden) ]
4709
4709
pub fn create_rpc_client_mocks ( ) -> crate :: mock_sender:: Mocks {
4710
- let mut mocks = std :: collections :: HashMap :: new ( ) ;
4710
+ let mut mocks = crate :: mock_sender :: Mocks :: default ( ) ;
4711
4711
4712
4712
let get_account_request = RpcRequest :: GetAccountInfo ;
4713
4713
let get_account_response = serde_json:: to_value ( Response {
Original file line number Diff line number Diff line change @@ -3677,7 +3677,7 @@ impl RpcClient {
3677
3677
/// Mocks for documentation examples
3678
3678
#[ doc( hidden) ]
3679
3679
pub fn create_rpc_client_mocks ( ) -> crate :: mock_sender:: Mocks {
3680
- let mut mocks = std :: collections :: HashMap :: new ( ) ;
3680
+ let mut mocks = crate :: mock_sender :: Mocks :: default ( ) ;
3681
3681
3682
3682
let get_account_request = RpcRequest :: GetAccountInfo ;
3683
3683
let get_account_response = serde_json:: to_value ( Response {
You can’t perform that action at this time.
0 commit comments