Skip to content

Commit 3bfde7b

Browse files
danieleadesdaniel.eades
authored andcommitted
use 'Self'
1 parent 1f4dcfe commit 3bfde7b

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

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
}

src/alphabet.rs

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

@@ -37,7 +37,7 @@ impl Alphabet {
3737
index += 1;
3838
}
3939

40-
Alphabet { symbols }
40+
Self { symbols }
4141
}
4242

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

102102
fn try_from(value: &str) -> Result<Self, Self::Error> {
103-
Alphabet::from_str(value)
103+
Self::from_str(value)
104104
}
105105
}
106106

src/engine/fast_portable/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub struct FastPortableEstimate {
2727
}
2828

2929
impl FastPortableEstimate {
30-
pub(crate) fn from(input_len: usize) -> FastPortableEstimate {
31-
FastPortableEstimate {
30+
pub(crate) fn from(input_len: usize) -> Self {
31+
Self {
3232
num_chunks: num_chunks(input_len),
3333
}
3434
}

src/engine/fast_portable/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ impl FastPortable {
2525
///
2626
/// While not very expensive to initialize, ideally these should be cached
2727
/// if the engine will be used repeatedly.
28-
pub const fn from(alphabet: &Alphabet, config: FastPortableConfig) -> FastPortable {
29-
FastPortable {
28+
pub const fn from(alphabet: &Alphabet, config: FastPortableConfig) -> Self {
29+
Self {
3030
encode_table: encode_table(alphabet),
3131
decode_table: decode_table(alphabet),
3232
config,
@@ -244,8 +244,8 @@ impl FastPortableConfig {
244244
///
245245
/// This probably matches most people's expectations, but consider disabling padding to save
246246
/// a few bytes unless you specifically need it for compatibility with some legacy system.
247-
pub const fn new() -> FastPortableConfig {
248-
FastPortableConfig {
247+
pub const fn new() -> Self {
248+
Self {
249249
// RFC states that padding must be applied by default
250250
encode_padding: true,
251251
decode_allow_trailing_bits: false,
@@ -262,8 +262,8 @@ impl FastPortableConfig {
262262
///
263263
/// For new applications, consider not using padding if the decoders you're using don't require
264264
/// padding to be present.
265-
pub const fn with_encode_padding(self, padding: bool) -> FastPortableConfig {
266-
FastPortableConfig {
265+
pub const fn with_encode_padding(self, padding: bool) -> Self {
266+
Self {
267267
encode_padding: padding,
268268
..self
269269
}
@@ -276,8 +276,8 @@ impl FastPortableConfig {
276276
/// character as per [forgiving-base64 decode](https://infra.spec.whatwg.org/#forgiving-base64-decode).
277277
/// If invalid trailing bits are present and this is `true`, those bits will
278278
/// be silently ignored, else `DecodeError::InvalidLastSymbol` will be emitted.
279-
pub const fn with_decode_allow_trailing_bits(self, allow: bool) -> FastPortableConfig {
280-
FastPortableConfig {
279+
pub const fn with_decode_allow_trailing_bits(self, allow: bool) -> Self {
280+
Self {
281281
decode_allow_trailing_bits: allow,
282282
..self
283283
}
@@ -287,7 +287,7 @@ impl FastPortableConfig {
287287
impl Default for FastPortableConfig {
288288
/// Delegates to [FastPortableConfig::new].
289289
fn default() -> Self {
290-
FastPortableConfig::new()
290+
Self::new()
291291
}
292292
}
293293

src/engine/naive.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ impl Naive {
1616
const ENCODE_INPUT_CHUNK_SIZE: usize = 3;
1717
const DECODE_INPUT_CHUNK_SIZE: usize = 4;
1818

19-
pub const fn from(alphabet: &Alphabet, config: NaiveConfig) -> Naive {
20-
Naive {
19+
pub const fn from(alphabet: &Alphabet, config: NaiveConfig) -> Self {
20+
Self {
2121
encode_table: encode_table(alphabet),
2222
decode_table: decode_table(alphabet),
2323
config,
@@ -44,17 +44,17 @@ impl Engine for Naive {
4444

4545
const LOW_SIX_BITS: u32 = 0x3F;
4646

47-
let rem = input.len() % Naive::ENCODE_INPUT_CHUNK_SIZE;
47+
let rem = input.len() % Self::ENCODE_INPUT_CHUNK_SIZE;
4848
// will never underflow
4949
let complete_chunk_len = input.len() - rem;
5050

5151
let mut input_index = 0_usize;
5252
let mut output_index = 0_usize;
5353
if let Some(last_complete_chunk_index) =
54-
complete_chunk_len.checked_sub(Naive::ENCODE_INPUT_CHUNK_SIZE)
54+
complete_chunk_len.checked_sub(Self::ENCODE_INPUT_CHUNK_SIZE)
5555
{
5656
while input_index <= last_complete_chunk_index {
57-
let chunk = &input[input_index..input_index + Naive::ENCODE_INPUT_CHUNK_SIZE];
57+
let chunk = &input[input_index..input_index + Self::ENCODE_INPUT_CHUNK_SIZE];
5858

5959
// populate low 24 bits from 3 bytes
6060
let chunk_int: u32 =
@@ -68,7 +68,7 @@ impl Engine for Naive {
6868
output[output_index + 3] =
6969
self.encode_table[chunk_int.bitand(LOW_SIX_BITS) as usize];
7070

71-
input_index += Naive::ENCODE_INPUT_CHUNK_SIZE;
71+
input_index += Self::ENCODE_INPUT_CHUNK_SIZE;
7272
output_index += 4;
7373
}
7474
}
@@ -127,22 +127,22 @@ impl Engine for Naive {
127127
const BOTTOM_BYTE: u32 = 0xFF;
128128

129129
// can only use the main loop on non-trailing chunks
130-
if input.len() > Naive::DECODE_INPUT_CHUNK_SIZE {
130+
if input.len() > Self::DECODE_INPUT_CHUNK_SIZE {
131131
// skip the last chunk, whether it's partial or full, since it might
132132
// have padding, and start at the beginning of the chunk before that
133133
let last_complete_chunk_start_index = estimate.complete_chunk_len
134134
- if estimate.rem == 0 {
135135
// Trailing chunk is also full chunk, so there must be at least 2 chunks, and
136136
// this won't underflow
137-
Naive::DECODE_INPUT_CHUNK_SIZE * 2
137+
Self::DECODE_INPUT_CHUNK_SIZE * 2
138138
} else {
139139
// Trailing chunk is partial, so it's already excluded in
140140
// complete_chunk_len
141-
Naive::DECODE_INPUT_CHUNK_SIZE
141+
Self::DECODE_INPUT_CHUNK_SIZE
142142
};
143143

144144
while input_index <= last_complete_chunk_start_index {
145-
let chunk = &input[input_index..input_index + Naive::DECODE_INPUT_CHUNK_SIZE];
145+
let chunk = &input[input_index..input_index + Self::DECODE_INPUT_CHUNK_SIZE];
146146
let decoded_int: u32 = self.decode_byte_into_u32(input_index, chunk[0])?.shl(18)
147147
| self
148148
.decode_byte_into_u32(input_index + 1, chunk[1])?
@@ -154,7 +154,7 @@ impl Engine for Naive {
154154
output[output_index + 1] = decoded_int.shr(8_u8).bitand(BOTTOM_BYTE) as u8;
155155
output[output_index + 2] = decoded_int.bitand(BOTTOM_BYTE) as u8;
156156

157-
input_index += Naive::DECODE_INPUT_CHUNK_SIZE;
157+
input_index += Self::DECODE_INPUT_CHUNK_SIZE;
158158
output_index += 3;
159159
}
160160
}
@@ -273,11 +273,11 @@ pub struct NaiveEstimate {
273273
}
274274

275275
impl NaiveEstimate {
276-
fn from(input_len: usize) -> NaiveEstimate {
276+
fn from(input_len: usize) -> Self {
277277
let rem = input_len % Naive::DECODE_INPUT_CHUNK_SIZE;
278278
let complete_chunk_len = input_len - rem;
279279

280-
NaiveEstimate {
280+
Self {
281281
rem,
282282
complete_chunk_len,
283283
}

0 commit comments

Comments
 (0)