Skip to content

Commit 936569a

Browse files
Move re-exports from engine to prelude
1 parent 53e1091 commit 936569a

File tree

18 files changed

+139
-117
lines changed

18 files changed

+139
-117
lines changed

RELEASE-NOTES.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
1-
# 0.21.0-beta.1
2-
3-
## Breaking changes
4-
5-
- `FastPortable` was only meant to be an interim name, and shouldn't have shipped in 0.20. It is now `GeneralPurpose` to
6-
make its intended usage more clear.
7-
- `GeneralPurpose` and its config are now `pub use`'d in the `engine` module for convenience.
8-
- Change a few `from()` functions to be `new()`. `from()` causes confusing compiler errors because of confusion
9-
with `From::from`, and is a little misleading because some of those invocations are not very cheap as one would
10-
usually expect from a `from` call.
11-
- `encode*` and `decode*` top level functions are now methods on `Engine`.
12-
- `DEFAULT_ENGINE` was replaced by `engine::general_purpose::STANDARD`
13-
- Predefined engine consts `engine::general_purpose::{STANDARD, STANDARD_NO_PAD, URL_SAFE, URL_SAFE_NO_PAD}`
14-
- These are `pub use`d into `engine` as well
15-
- The `*_slice` decode/encode functions now return an error instead of panicking when the output slice is too small
16-
- As part of this, there isn't now a public way to decode into a slice _exactly_ the size needed for inputs that
17-
aren't multiples of 4 tokens. If adding up to 2 bytes to always be a multiple of 3 bytes for the decode buffer is
18-
a problem, file an issue.
1+
# 0.21.0
192

20-
## Other changes
3+
(not yet released)
214

22-
- `decoded_len_estimate()` is provided to make it easy to size decode buffers correctly.
235

246
## Migration
257

268
### Functions
279

28-
| < 0.20 function | 0.21 equivalent |
29-
|-------------------------|-----------------------------|
30-
| `encode()` | `engine::STANDARD.encode()` |
31-
| `encode_config()` | `engine.encode()` |
32-
| `encode_config_buf()` | `engine.encode_string()` |
33-
| `encode_config_slice()` | `engine.encode_slice()` |
34-
| `decode()` | `engine::STANDARD.decode()` |
35-
| `decode_config()` | `engine.decode()` |
36-
| `decode_config_buf()` | `engine.decode_vec()` |
37-
| `decode_config_slice()` | `engine.decode_slice()` |
10+
| < 0.20 function | 0.21 equivalent |
11+
|-------------------------|-------------------------------------------------------------------------------------|
12+
| `encode()` | `engine::general_purpose::STANDARD.encode()` or `prelude::BASE64_STANDARD.encode()` |
13+
| `encode_config()` | `engine.encode()` |
14+
| `encode_config_buf()` | `engine.encode_string()` |
15+
| `encode_config_slice()` | `engine.encode_slice()` |
16+
| `decode()` | `engine::general_purpose::STANDARD.decode()` or `prelude::BASE64_STANDARD.decode()` |
17+
| `decode_config()` | `engine.decode()` |
18+
| `decode_config_buf()` | `engine.decode_vec()` |
19+
| `decode_config_slice()` | `engine.decode_slice()` |
3820

3921
The short-lived 0.20 functions were the 0.13 functions with `config` replaced with `engine`.
4022

@@ -55,6 +37,36 @@ precisely, see the following table.
5537
| URL_SAFE | URL_SAFE | true | Indifferent |
5638
| URL_SAFE_NO_PAD | URL_SAFE | false | Indifferent |
5739

40+
41+
# 0.21.0-beta.2
42+
43+
## Breaking changes
44+
45+
- Re-exports of preconfigured engines in `engine` are removed in favor of `base64::prelude::...` that are better suited to those who wish to `use` the entire path to a name.
46+
47+
# 0.21.0-beta.1
48+
49+
## Breaking changes
50+
51+
- `FastPortable` was only meant to be an interim name, and shouldn't have shipped in 0.20. It is now `GeneralPurpose` to
52+
make its intended usage more clear.
53+
- `GeneralPurpose` and its config are now `pub use`'d in the `engine` module for convenience.
54+
- Change a few `from()` functions to be `new()`. `from()` causes confusing compiler errors because of confusion
55+
with `From::from`, and is a little misleading because some of those invocations are not very cheap as one would
56+
usually expect from a `from` call.
57+
- `encode*` and `decode*` top level functions are now methods on `Engine`.
58+
- `DEFAULT_ENGINE` was replaced by `engine::general_purpose::STANDARD`
59+
- Predefined engine consts `engine::general_purpose::{STANDARD, STANDARD_NO_PAD, URL_SAFE, URL_SAFE_NO_PAD}`
60+
- These are `pub use`d into `engine` as well
61+
- The `*_slice` decode/encode functions now return an error instead of panicking when the output slice is too small
62+
- As part of this, there isn't now a public way to decode into a slice _exactly_ the size needed for inputs that
63+
aren't multiples of 4 tokens. If adding up to 2 bytes to always be a multiple of 3 bytes for the decode buffer is
64+
a problem, file an issue.
65+
66+
## Other changes
67+
68+
- `decoded_len_estimate()` is provided to make it easy to size decode buffers correctly.
69+
5870
# 0.20.0
5971

6072
## Breaking changes

benches/benchmarks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate criterion;
33

44
use base64::{
55
display,
6-
engine::{Engine, STANDARD},
6+
engine::{general_purpose::STANDARD, Engine},
77
write,
88
};
99
use criterion::{black_box, Bencher, BenchmarkId, Criterion, Throughput};

fuzz/fuzzers/roundtrip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[macro_use] extern crate libfuzzer_sys;
33
extern crate base64;
44

5-
use base64::{Engine as _, engine::STANDARD};
5+
use base64::{Engine as _, engine::general_purpose::STANDARD};
66

77
fuzz_target!(|data: &[u8]| {
88
let encoded = STANDARD.encode(data);

src/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::engine::{DecodeEstimate, Engine, STANDARD};
1+
use crate::engine::{general_purpose::STANDARD, DecodeEstimate, Engine};
22
#[cfg(any(feature = "alloc", feature = "std", test))]
33
use alloc::vec::Vec;
44
use core::fmt;

src/display.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Enables base64'd output anywhere you might use a `Display` implementation, like a format string.
22
//!
33
//! ```
4-
//! use base64::display::Base64Display;
5-
//! use base64::engine::STANDARD;
4+
//! use base64::{display::Base64Display, engine::general_purpose::STANDARD};
65
//!
76
//! let data = vec![0x0, 0x1, 0x2, 0x3];
87
//! let wrapper = Base64Display::new(&data, &STANDARD);
@@ -59,7 +58,7 @@ mod tests {
5958
chunked_encode_matches_normal_encode_random, SinkTestHelper,
6059
};
6160
use super::*;
62-
use crate::engine::STANDARD;
61+
use crate::engine::general_purpose::STANDARD;
6362

6463
#[test]
6564
fn basic_display() {

src/encode.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::fmt;
55
use std::error;
66

77
#[cfg(any(feature = "alloc", feature = "std", test))]
8-
use crate::engine::STANDARD;
8+
use crate::engine::general_purpose::STANDARD;
99
use crate::engine::{Config, Engine};
1010
use crate::PAD_BYTE;
1111

@@ -161,10 +161,7 @@ mod tests {
161161

162162
use crate::{
163163
alphabet,
164-
engine::{
165-
general_purpose::{GeneralPurpose, NO_PAD},
166-
STANDARD,
167-
},
164+
engine::general_purpose::{GeneralPurpose, NO_PAD, STANDARD},
168165
tests::{assert_encode_sanity, random_config, random_engine},
169166
};
170167
use rand::{

src/engine/general_purpose/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn write_u64(output: &mut [u8], value: u64) {
326326
mod tests {
327327
use super::*;
328328

329-
use crate::engine::STANDARD;
329+
use crate::engine::general_purpose::STANDARD;
330330

331331
#[test]
332332
fn decode_chunk_precise_writes_only_6_bytes() {

src/engine/general_purpose/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn read_u64(s: &[u8]) -> u64 {
237237
///
238238
/// The constants [PAD] and [NO_PAD] cover most use cases.
239239
///
240-
/// To specify the characters used, see [crate::alphabet::Alphabet].
240+
/// To specify the characters used, see [Alphabet].
241241
#[derive(Clone, Copy, Debug)]
242242
pub struct GeneralPurposeConfig {
243243
encode_padding: bool,
@@ -325,16 +325,16 @@ impl Config for GeneralPurposeConfig {
325325
}
326326
}
327327

328-
/// A [GeneralPurpose] engine using the [crate::alphabet::STANDARD] base64 alphabet and [crate::engine::general_purpose::PAD] config.
328+
/// A [GeneralPurpose] engine using the [alphabet::STANDARD] base64 alphabet and [PAD] config.
329329
pub const STANDARD: GeneralPurpose = GeneralPurpose::new(&alphabet::STANDARD, PAD);
330330

331-
/// A [GeneralPurpose] engine using the [crate::alphabet::STANDARD] base64 alphabet and [crate::engine::general_purpose::NO_PAD] config.
331+
/// A [GeneralPurpose] engine using the [alphabet::STANDARD] base64 alphabet and [NO_PAD] config.
332332
pub const STANDARD_NO_PAD: GeneralPurpose = GeneralPurpose::new(&alphabet::STANDARD, NO_PAD);
333333

334-
/// A [GeneralPurpose] engine using the [crate::alphabet::URL_SAFE] base64 alphabet and [crate::engine::general_purpose::PAD] config.
334+
/// A [GeneralPurpose] engine using the [alphabet::URL_SAFE] base64 alphabet and [PAD] config.
335335
pub const URL_SAFE: GeneralPurpose = GeneralPurpose::new(&alphabet::URL_SAFE, PAD);
336336

337-
/// A [GeneralPurpose] engine using the [crate::alphabet::URL_SAFE] base64 alphabet and [crate::engine::general_purpose::NO_PAD] config.
337+
/// A [GeneralPurpose] engine using the [alphabet::URL_SAFE] base64 alphabet and [NO_PAD] config.
338338
pub const URL_SAFE_NO_PAD: GeneralPurpose = GeneralPurpose::new(&alphabet::URL_SAFE, NO_PAD);
339339

340340
/// Include padding bytes when encoding, and require that they be present when decoding.

src/engine/mod.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ mod naive;
1919
#[cfg(test)]
2020
mod tests;
2121

22-
pub use general_purpose::{
23-
GeneralPurpose, GeneralPurposeConfig, STANDARD, STANDARD_NO_PAD, URL_SAFE, URL_SAFE_NO_PAD,
24-
};
22+
pub use general_purpose::{GeneralPurpose, GeneralPurposeConfig};
2523

2624
/// An `Engine` provides low-level encoding and decoding operations that all other higher-level parts of the API use. Users of the library will generally not need to implement this.
2725
///
2826
/// Different implementations offer different characteristics. The library currently ships with
2927
/// [GeneralPurpose] that offers good speed and works on any CPU, with more choices
3028
/// coming later, like a constant-time one when side channel resistance is called for, and vendor-specific vectorized ones for more speed.
3129
///
32-
/// See [STANDARD] if you just want standard base64. Otherwise, when possible, it's
30+
/// See [general_purpose::STANDARD_NO_PAD] if you just want standard base64. Otherwise, when possible, it's
3331
/// recommended to store the engine in a `const` so that references to it won't pose any lifetime
3432
/// issues, and to avoid repeating the cost of engine setup.
3533
///
@@ -112,16 +110,15 @@ pub trait Engine: Send + Sync {
112110
/// # Example
113111
///
114112
/// ```rust
115-
/// use base64::Engine as _;
116-
/// const URL_SAFE_ENGINE: base64::engine::GeneralPurpose =
117-
/// base64::engine::GeneralPurpose::new(
118-
/// &base64::alphabet::URL_SAFE,
119-
/// base64::engine::general_purpose::NO_PAD);
113+
/// use base64::{Engine as _, engine::{self, general_purpose}, alphabet};
120114
///
121-
/// let b64 = base64::engine::STANDARD.encode(b"hello world~");
115+
/// let b64 = general_purpose::STANDARD.encode(b"hello world~");
122116
/// println!("{}", b64);
123117
///
124-
/// let b64_url = URL_SAFE_ENGINE.encode(b"hello internet~");
118+
/// const CUSTOM_ENGINE: engine::GeneralPurpose =
119+
/// engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::NO_PAD);
120+
///
121+
/// let b64_url = CUSTOM_ENGINE.encode(b"hello internet~");
125122
#[cfg(any(feature = "alloc", feature = "std", test))]
126123
fn encode<T: AsRef<[u8]>>(&self, input: T) -> String {
127124
let encoded_size = encoded_len(input.as_ref().len(), self.config().encode_padding())
@@ -139,18 +136,17 @@ pub trait Engine: Send + Sync {
139136
/// # Example
140137
///
141138
/// ```rust
142-
/// use base64::Engine as _;
143-
/// const URL_SAFE_ENGINE: base64::engine::GeneralPurpose =
144-
/// base64::engine::GeneralPurpose::new(
145-
/// &base64::alphabet::URL_SAFE,
146-
/// base64::engine::general_purpose::NO_PAD);
139+
/// use base64::{Engine as _, engine::{self, general_purpose}, alphabet};
140+
/// const CUSTOM_ENGINE: engine::GeneralPurpose =
141+
/// engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::NO_PAD);
142+
///
147143
/// fn main() {
148144
/// let mut buf = String::new();
149-
/// base64::engine::STANDARD.encode_string(b"hello world~", &mut buf);
145+
/// general_purpose::STANDARD.encode_string(b"hello world~", &mut buf);
150146
/// println!("{}", buf);
151147
///
152148
/// buf.clear();
153-
/// URL_SAFE_ENGINE.encode_string(b"hello internet~", &mut buf);
149+
/// CUSTOM_ENGINE.encode_string(b"hello internet~", &mut buf);
154150
/// println!("{}", buf);
155151
/// }
156152
/// ```
@@ -176,18 +172,18 @@ pub trait Engine: Send + Sync {
176172
/// # Example
177173
///
178174
/// ```rust
179-
/// use base64::{engine, Engine as _};
175+
/// use base64::{Engine as _, engine::general_purpose};
180176
/// let s = b"hello internet!";
181177
/// let mut buf = Vec::new();
182178
/// // make sure we'll have a slice big enough for base64 + padding
183179
/// buf.resize(s.len() * 4 / 3 + 4, 0);
184180
///
185-
/// let bytes_written = engine::STANDARD.encode_slice(s, &mut buf).unwrap();
181+
/// let bytes_written = general_purpose::STANDARD.encode_slice(s, &mut buf).unwrap();
186182
///
187183
/// // shorten our vec down to just what was written
188184
/// buf.truncate(bytes_written);
189185
///
190-
/// assert_eq!(s, engine::STANDARD.decode(&buf).unwrap().as_slice());
186+
/// assert_eq!(s, general_purpose::STANDARD.decode(&buf).unwrap().as_slice());
191187
/// ```
192188
fn encode_slice<T: AsRef<[u8]>>(
193189
&self,
@@ -216,17 +212,18 @@ pub trait Engine: Send + Sync {
216212
/// # Example
217213
///
218214
/// ```rust
219-
/// use base64::{Engine as _, Engine};
220-
///
221-
/// let bytes = base64::engine::STANDARD.decode("aGVsbG8gd29ybGR+Cg==").unwrap();
222-
/// println!("{:?}", bytes);
223-
///
224-
/// // custom engine setup
225-
/// let bytes_url = base64::engine::GeneralPurpose::new(
226-
/// &base64::alphabet::URL_SAFE,
227-
/// base64::engine::general_purpose::NO_PAD)
228-
/// .decode("aGVsbG8gaW50ZXJuZXR-Cg").unwrap();
229-
/// println!("{:?}", bytes_url);
215+
/// use base64::{Engine as _, alphabet, engine::{self, general_purpose}};
216+
///
217+
/// let bytes = general_purpose::STANDARD
218+
/// .decode("aGVsbG8gd29ybGR+Cg==").unwrap();
219+
/// println!("{:?}", bytes);
220+
///
221+
/// // custom engine setup
222+
/// let bytes_url = engine::GeneralPurpose::new(
223+
/// &alphabet::URL_SAFE,
224+
/// general_purpose::NO_PAD)
225+
/// .decode("aGVsbG8gaW50ZXJuZXR-Cg").unwrap();
226+
/// println!("{:?}", bytes_url);
230227
/// ```
231228
///
232229
/// # Panics
@@ -253,25 +250,22 @@ pub trait Engine: Send + Sync {
253250
/// # Example
254251
///
255252
/// ```rust
256-
/// const URL_SAFE_ENGINE: base64::engine::GeneralPurpose =
257-
/// base64::engine::GeneralPurpose::new(
258-
/// &base64::alphabet::URL_SAFE,
259-
/// base64::engine::general_purpose::PAD);
253+
/// use base64::{Engine as _, alphabet, engine::{self, general_purpose}};
254+
/// const CUSTOM_ENGINE: engine::GeneralPurpose =
255+
/// engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::PAD);
260256
///
261257
/// fn main() {
262258
/// use base64::Engine;
263259
/// let mut buffer = Vec::<u8>::new();
264260
/// // with the default engine
265-
/// base64::engine::STANDARD.decode_vec(
266-
/// "aGVsbG8gd29ybGR+Cg==",
267-
/// &mut buffer,
268-
/// ).unwrap();
261+
/// general_purpose::STANDARD
262+
/// .decode_vec("aGVsbG8gd29ybGR+Cg==", &mut buffer,).unwrap();
269263
/// println!("{:?}", buffer);
270264
///
271265
/// buffer.clear();
272266
///
273267
/// // with a custom engine
274-
/// URL_SAFE_ENGINE.decode_vec(
268+
/// CUSTOM_ENGINE.decode_vec(
275269
/// "aGVsbG8gaW50ZXJuZXR-Cg==",
276270
/// &mut buffer,
277271
/// ).unwrap();

0 commit comments

Comments
 (0)