@@ -30,11 +30,9 @@ pub enum DecodeError {
30
30
impl fmt:: Display for DecodeError {
31
31
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
32
32
match * self {
33
- DecodeError :: InvalidByte ( index, byte) => {
34
- write ! ( f, "Invalid byte {}, offset {}." , byte, index)
35
- }
36
- DecodeError :: InvalidLength => write ! ( f, "Encoded text cannot have a 6-bit remainder." ) ,
37
- DecodeError :: InvalidLastSymbol ( index, byte) => {
33
+ Self :: InvalidByte ( index, byte) => write ! ( f, "Invalid byte {}, offset {}." , byte, index) ,
34
+ Self :: InvalidLength => write ! ( f, "Encoded text cannot have a 6-bit remainder." ) ,
35
+ Self :: InvalidLastSymbol ( index, byte) => {
38
36
write ! ( f, "Invalid last symbol {}, offset {}." , byte, index)
39
37
}
40
38
}
@@ -45,9 +43,9 @@ impl fmt::Display for DecodeError {
45
43
impl error:: Error for DecodeError {
46
44
fn description ( & self ) -> & str {
47
45
match * self {
48
- DecodeError :: InvalidByte ( _, _) => "invalid byte" ,
49
- DecodeError :: InvalidLength => "invalid length" ,
50
- DecodeError :: InvalidLastSymbol ( _, _) => "invalid last symbol" ,
46
+ Self :: InvalidByte ( _, _) => "invalid byte" ,
47
+ Self :: InvalidLength => "invalid length" ,
48
+ Self :: InvalidLastSymbol ( _, _) => "invalid last symbol" ,
51
49
}
52
50
}
53
51
@@ -62,12 +60,8 @@ impl error::Error for DecodeError {
62
60
///# Example
63
61
///
64
62
///```rust
65
- ///extern crate base64;
66
- ///
67
- ///fn main() {
68
- /// let bytes = base64::decode("aGVsbG8gd29ybGQ=").unwrap();
69
- /// println!("{:?}", bytes);
70
- ///}
63
+ /// let bytes = base64::decode("aGVsbG8gd29ybGQ=").unwrap();
64
+ /// println!("{:?}", bytes);
71
65
///```
72
66
#[ cfg( any( feature = "alloc" , feature = "std" , test) ) ]
73
67
pub fn decode < T : AsRef < [ u8 ] > > ( input : T ) -> Result < Vec < u8 > , DecodeError > {
@@ -80,9 +74,6 @@ pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
80
74
///# Example
81
75
///
82
76
///```rust
83
- ///extern crate base64;
84
- ///
85
- ///fn main() {
86
77
/// let bytes = base64::decode_engine(
87
78
/// "aGVsbG8gd29ybGR+Cg==",
88
79
/// &base64::engine::DEFAULT_ENGINE,
@@ -98,7 +89,6 @@ pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
98
89
///
99
90
/// ).unwrap();
100
91
/// println!("{:?}", bytes_url);
101
- ///}
102
92
///```
103
93
#[ cfg( any( feature = "alloc" , feature = "std" , test) ) ]
104
94
pub fn decode_engine < E : Engine , T : AsRef < [ u8 ] > > (
@@ -117,8 +107,6 @@ pub fn decode_engine<E: Engine, T: AsRef<[u8]>>(
117
107
///# Example
118
108
///
119
109
///```rust
120
- ///extern crate base64;
121
- ///
122
110
///const URL_SAFE_ENGINE: base64::engine::fast_portable::FastPortable =
123
111
/// base64::engine::fast_portable::FastPortable::from(
124
112
/// &base64::alphabet::URL_SAFE,
@@ -162,11 +150,8 @@ pub fn decode_engine_vec<E: Engine, T: AsRef<[u8]>>(
162
150
. expect ( "Overflow when calculating output buffer length" ) ;
163
151
buffer. resize ( total_len_estimate, 0 ) ;
164
152
165
- let bytes_written;
166
- {
167
- let buffer_slice = & mut buffer. as_mut_slice ( ) [ starting_output_len..] ;
168
- bytes_written = engine. decode ( input_bytes, buffer_slice, estimate) ?;
169
- }
153
+ let buffer_slice = & mut buffer. as_mut_slice ( ) [ starting_output_len..] ;
154
+ let bytes_written = engine. decode ( input_bytes, buffer_slice, estimate) ?;
170
155
171
156
buffer. truncate ( starting_output_len + bytes_written) ;
172
157
0 commit comments