@@ -18,7 +18,6 @@ use serde::{
18
18
use std:: {
19
19
convert:: TryFrom ,
20
20
fmt,
21
- io,
22
21
hash,
23
22
iter:: FromIterator ,
24
23
net:: { IpAddr , Ipv4Addr , Ipv6Addr } ,
@@ -70,9 +69,9 @@ impl Multiaddr {
70
69
/// ```
71
70
///
72
71
pub fn push ( & mut self , p : Protocol < ' _ > ) {
73
- let mut w = Buffer :: from_ref ( self . as_ref ( ) ) ;
72
+ let mut w: smallvec :: SmallVec < [ u8 ; 32 ] > = self . as_ref ( ) . into ( ) ;
74
73
p. write_bytes ( & mut w) . expect ( "Writing to a `Buffer` never fails." ) ;
75
- self . storage = w . to_storage ( ) ;
74
+ self . storage = Storage :: from_slice ( & w ) ;
76
75
}
77
76
78
77
/// Pops the last `Protocol` of this multiaddr, or `None` if the multiaddr is empty.
@@ -104,9 +103,7 @@ impl Multiaddr {
104
103
105
104
/// Like [`Multiaddr::push`] but consumes `self`.
106
105
pub fn with ( mut self , p : Protocol < ' _ > ) -> Self {
107
- let mut w = Buffer :: from_ref ( self . as_ref ( ) ) ;
108
- p. write_bytes ( & mut w) . expect ( "Writing to a `Buffer` never fails." ) ;
109
- self . storage = w. to_storage ( ) ;
106
+ self . push ( p) ;
110
107
self
111
108
}
112
109
@@ -423,26 +420,3 @@ macro_rules! multiaddr {
423
420
}
424
421
}
425
422
}
426
-
427
- struct Buffer ( smallvec:: SmallVec < [ u8 ; 32 ] > ) ;
428
-
429
- impl Buffer {
430
- fn from_ref ( data : & [ u8 ] ) -> Self {
431
- Self ( data. into ( ) )
432
- }
433
-
434
- fn to_storage ( self ) -> Storage {
435
- Storage :: from_slice ( & self . 0 )
436
- }
437
- }
438
-
439
- impl io:: Write for Buffer {
440
- fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
441
- self . 0 . extend_from_slice ( buf) ;
442
- Ok ( buf. len ( ) )
443
- }
444
-
445
- fn flush ( & mut self ) -> io:: Result < ( ) > {
446
- Ok ( ( ) )
447
- }
448
- }
0 commit comments