File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2213,6 +2213,21 @@ impl<R: Read> Deserializer<R> {
22132213 }
22142214 }
22152215
2216+ /// Gets a reference to the underlying reader in this decoder.
2217+ pub fn get_ref ( & self ) -> & R {
2218+ & self . rd
2219+ }
2220+
2221+ /// Gets a mutable reference to the underlying reader in this decoder.
2222+ pub fn get_mut ( & mut self ) -> & mut R {
2223+ & mut self . rd
2224+ }
2225+
2226+ /// Consumes this decoder returning the underlying reader.
2227+ pub fn into_inner ( self ) -> R {
2228+ self . rd
2229+ }
2230+
22162231 fn read_str < V > ( & mut self , len : u32 , mut visitor : V ) -> Result < V :: Value >
22172232 where V : serde:: de:: Visitor
22182233 {
@@ -2255,8 +2270,6 @@ impl<R: Read> Deserializer<R> {
22552270
22562271 visitor. visit_bytes ( & mut self . buf [ ..] )
22572272 }
2258-
2259- // TODO: Add an ability to borrow underlying reader and to destruct this decoder.
22602273}
22612274
22622275/// Unstable: docs; examples; incomplete
Original file line number Diff line number Diff line change 11mod encode;
22mod decode;
33mod rserialize;
4+ mod serde;
Original file line number Diff line number Diff line change 1+ use std:: io:: Cursor ;
2+
3+ use serde:: Deserialize ;
4+
5+ use msgpack:: Deserializer ;
6+
7+ #[ test]
8+ fn pass_deserializer_get_ref ( ) {
9+ let buf = [ 0xc0 ] ;
10+ let cur = Cursor :: new ( & buf[ ..] ) ;
11+
12+ let mut de = Deserializer :: new ( cur) ;
13+
14+ assert_eq ! ( ( ) , Deserialize :: deserialize( & mut de) . ok( ) . unwrap( ) ) ;
15+ assert_eq ! ( 1 , de. get_ref( ) . position( ) ) ;
16+ }
17+
18+ #[ test]
19+ fn pass_deserializer_get_mut ( ) {
20+ let buf = [ 0xc0 ] ;
21+ let cur = Cursor :: new ( & buf[ ..] ) ;
22+
23+ let mut de = Deserializer :: new ( cur) ;
24+
25+ assert_eq ! ( ( ) , Deserialize :: deserialize( & mut de) . ok( ) . unwrap( ) ) ;
26+ de. get_mut ( ) . set_position ( 0 ) ;
27+
28+ assert_eq ! ( ( ) , Deserialize :: deserialize( & mut de) . ok( ) . unwrap( ) ) ;
29+ }
30+
31+ #[ test]
32+ fn pass_deserializer_into_inner ( ) {
33+ let buf = [ 0xc0 ] ;
34+ let cur = Cursor :: new ( & buf[ ..] ) ;
35+
36+ let mut de = Deserializer :: new ( cur) ;
37+
38+ assert_eq ! ( ( ) , Deserialize :: deserialize( & mut de) . ok( ) . unwrap( ) ) ;
39+ let cur = de. into_inner ( ) ;
40+
41+ assert_eq ! ( 1 , cur. position( ) ) ;
42+ }
You can’t perform that action at this time.
0 commit comments