Skip to content

Commit 3b42c50

Browse files
Merge branch 'refactor/code-quality' of https://github.com/danieleades/rust-base64 into danieleades-refactor/code-quality
2 parents c3e790c + 96f9d47 commit 3b42c50

26 files changed

+134
-194
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ This library's goals are to be *correct* and *fast*. It's thoroughly tested and
1313
## Example
1414

1515
```rust
16-
extern crate base64;
17-
1816
use base64::{encode, decode};
1917

2018
fn main() {

benches/benchmarks.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
extern crate base64;
21
#[macro_use]
32
extern crate criterion;
4-
extern crate rand;
53

64
use base64::display;
75
use base64::{

examples/base64.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ enum Alphabet {
1515

1616
impl Default for Alphabet {
1717
fn default() -> Self {
18-
Alphabet::Standard
18+
Self::Standard
1919
}
2020
}
2121

2222
impl FromStr for Alphabet {
2323
type Err = String;
24-
fn from_str(s: &str) -> Result<Alphabet, String> {
24+
fn from_str(s: &str) -> Result<Self, String> {
2525
match s {
26-
"standard" => Ok(Alphabet::Standard),
27-
"urlsafe" => Ok(Alphabet::UrlSafe),
26+
"standard" => Ok(Self::Standard),
27+
"urlsafe" => Ok(Self::UrlSafe),
2828
_ => Err(format!("alphabet '{}' unrecognized", s)),
2929
}
3030
}

fuzz/fuzzers/decode_random.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![no_main]
22
#[macro_use] extern crate libfuzzer_sys;
3-
extern crate base64;
43

54
use base64::*;
65

fuzz/fuzzers/roundtrip.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![no_main]
22
#[macro_use] extern crate libfuzzer_sys;
3-
extern crate base64;
43

54
use base64::engine::DEFAULT_ENGINE;
65

fuzz/fuzzers/roundtrip_no_pad.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![no_main]
22
#[macro_use] extern crate libfuzzer_sys;
3-
extern crate base64;
43
use base64::engine::fast_portable;
54

65
fuzz_target!(|data: &[u8]| {

fuzz/fuzzers/roundtrip_random_config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![no_main]
22
#[macro_use] extern crate libfuzzer_sys;
3-
extern crate base64;
43

54
use base64::*;
65

fuzz/fuzzers/utils.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
extern crate base64;
2-
extern crate rand;
3-
extern crate rand_pcg;
4-
extern crate ring;
5-
61
use base64::{alphabet, engine::fast_portable};
72
use self::rand::{Rng, SeedableRng};
83
use self::rand_pcg::Pcg32;

src/alphabet.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct Alphabet {
2727
impl Alphabet {
2828
/// Performs no checks so that it can be const.
2929
/// Used only for known-valid strings.
30-
const fn from_str_unchecked(alphabet: &str) -> Alphabet {
30+
const fn from_str_unchecked(alphabet: &str) -> Self {
3131
let mut symbols = [0_u8; ALPHABET_SIZE];
3232
let source_bytes = alphabet.as_bytes();
3333

@@ -38,7 +38,7 @@ impl Alphabet {
3838
index += 1;
3939
}
4040

41-
Alphabet { symbols }
41+
Self { symbols }
4242
}
4343

4444
/// Create an `Alphabet` from a string of 64 unique printable ASCII bytes.
@@ -97,7 +97,7 @@ impl convert::TryFrom<&str> for Alphabet {
9797
type Error = ParseAlphabetError;
9898

9999
fn try_from(value: &str) -> Result<Self, Self::Error> {
100-
Alphabet::from_str(value)
100+
Self::from_str(value)
101101
}
102102
}
103103

@@ -117,10 +117,10 @@ pub enum ParseAlphabetError {
117117
impl fmt::Display for ParseAlphabetError {
118118
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119119
match self {
120-
ParseAlphabetError::InvalidLength => write!(f, "Invalid length - must be 64 bytes"),
121-
ParseAlphabetError::DuplicatedByte(b) => write!(f, "Duplicated byte: {:#04x}", b),
122-
ParseAlphabetError::UnprintableByte(b) => write!(f, "Unprintable byte: {:#04x}", b),
123-
ParseAlphabetError::ReservedByte(b) => write!(f, "Reserved byte: {:#04x}", b),
120+
Self::InvalidLength => write!(f, "Invalid length - must be 64 bytes"),
121+
Self::DuplicatedByte(b) => write!(f, "Duplicated byte: {:#04x}", b),
122+
Self::UnprintableByte(b) => write!(f, "Unprintable byte: {:#04x}", b),
123+
Self::ReservedByte(b) => write!(f, "Reserved byte: {:#04x}", b),
124124
}
125125
}
126126
}
@@ -238,6 +238,6 @@ mod tests {
238238
STANDARD,
239239
Alphabet::try_from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
240240
.unwrap()
241-
)
241+
);
242242
}
243243
}

src/chunked_encoder.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,13 @@ pub mod tests {
201201

202202
fn chunked_encode_str(bytes: &[u8], config: FastPortableConfig) -> String {
203203
let mut s = String::new();
204-
{
205-
let mut sink = StringSink::from(&mut s);
206-
let engine = FastPortable::from(&STANDARD, config);
207-
let encoder = ChunkedEncoder::from(&engine);
208-
encoder.encode(bytes, &mut sink).unwrap();
209-
}
210204

211-
return s;
205+
let mut sink = StringSink::from(&mut s);
206+
let engine = FastPortable::from(&STANDARD, config);
207+
let encoder = ChunkedEncoder::from(&engine);
208+
encoder.encode(bytes, &mut sink).unwrap();
209+
210+
s
212211
}
213212

214213
// An abstraction around sinks so that we can have tests that easily to any sink implementation
@@ -222,10 +221,8 @@ pub mod tests {
222221
fn encode_to_string<E: Engine>(&self, engine: &E, bytes: &[u8]) -> String {
223222
let encoder = ChunkedEncoder::from(engine);
224223
let mut s = String::new();
225-
{
226-
let mut sink = StringSink::from(&mut s);
227-
encoder.encode(bytes, &mut sink).unwrap();
228-
}
224+
let mut sink = StringSink::from(&mut s);
225+
encoder.encode(bytes, &mut sink).unwrap();
229226

230227
s
231228
}

0 commit comments

Comments
 (0)