Skip to content

Commit

Permalink
Merge branch 'master' into nwalfield-streaming-reader
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallpierce committed Mar 8, 2020
2 parents 0585b03 + da57bf5 commit 61af8bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ matrix:
install:
# For test coverage. In install step so that it can use cache.
- cargo tarpaulin --version || RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install --force cargo-tarpaulin
- cargo +nightly install cargo-fuzz -Z install-upgrade
- cargo +nightly install cargo-fuzz

# no_std
- rust: stable
Expand Down
15 changes: 6 additions & 9 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl error::Error for DecodeError {
///}
///```
#[cfg(any(feature = "alloc", feature = "std", test))]
pub fn decode<T: ?Sized + AsRef<[u8]>>(input: &T) -> Result<Vec<u8>, DecodeError> {
pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
decode_config(input, STANDARD)
}

Expand All @@ -102,10 +102,7 @@ pub fn decode<T: ?Sized + AsRef<[u8]>>(input: &T) -> Result<Vec<u8>, DecodeError
///}
///```
#[cfg(any(feature = "alloc", feature = "std", test))]
pub fn decode_config<T: ?Sized + AsRef<[u8]>>(
input: &T,
config: Config,
) -> Result<Vec<u8>, DecodeError> {
pub fn decode_config<T: AsRef<[u8]>>(input: T, config: Config) -> Result<Vec<u8>, DecodeError> {
let mut buffer = Vec::<u8>::with_capacity(input.as_ref().len() * 4 / 3);

decode_config_buf(input, config, &mut buffer).map(|_| buffer)
Expand Down Expand Up @@ -133,8 +130,8 @@ pub fn decode_config<T: ?Sized + AsRef<[u8]>>(
///}
///```
#[cfg(any(feature = "alloc", feature = "std", test))]
pub fn decode_config_buf<T: ?Sized + AsRef<[u8]>>(
input: &T,
pub fn decode_config_buf<T: AsRef<[u8]>>(
input: T,
config: Config,
buffer: &mut Vec<u8>,
) -> Result<(), DecodeError> {
Expand Down Expand Up @@ -169,8 +166,8 @@ pub fn decode_config_buf<T: ?Sized + AsRef<[u8]>>(
/// input, rounded up, or in other words `(input_len + 3) / 4 * 3`.
///
/// If the slice is not large enough, this will panic.
pub fn decode_config_slice<T: ?Sized + AsRef<[u8]>>(
input: &T,
pub fn decode_config_slice<T: AsRef<[u8]>>(
input: T,
config: Config,
output: &mut [u8],
) -> Result<usize, DecodeError> {
Expand Down
15 changes: 5 additions & 10 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use core::convert::TryInto;
///}
///```
#[cfg(any(feature = "alloc", feature = "std", test))]
pub fn encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
pub fn encode<T: AsRef<[u8]>>(input: T) -> String {
encode_config(input, STANDARD)
}

Expand All @@ -41,14 +41,13 @@ pub fn encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
///}
///```
#[cfg(any(feature = "alloc", feature = "std", test))]
pub fn encode_config<T: ?Sized + AsRef<[u8]>>(input: &T, config: Config) -> String {
pub fn encode_config<T: AsRef<[u8]>>(input: T, config: Config) -> String {
let mut buf = match encoded_size(input.as_ref().len(), config) {
Some(n) => vec![0; n],
None => panic!("integer overflow when calculating buffer size"),
};

let encoded_len = encode_config_slice(input.as_ref(), config, &mut buf[..]);
debug_assert_eq!(encoded_len, buf.len());
encode_with_padding(input.as_ref(), config, buf.len(), &mut buf[..]);

String::from_utf8(buf).expect("Invalid UTF8")
}
Expand All @@ -72,7 +71,7 @@ pub fn encode_config<T: ?Sized + AsRef<[u8]>>(input: &T, config: Config) -> Stri
///}
///```
#[cfg(any(feature = "alloc", feature = "std", test))]
pub fn encode_config_buf<T: ?Sized + AsRef<[u8]>>(input: &T, config: Config, buf: &mut String) {
pub fn encode_config_buf<T: AsRef<[u8]>>(input: T, config: Config, buf: &mut String) {
let input_bytes = input.as_ref();

{
Expand Down Expand Up @@ -115,11 +114,7 @@ pub fn encode_config_buf<T: ?Sized + AsRef<[u8]>>(input: &T, config: Config, buf
/// assert_eq!(s, base64::decode(&buf).unwrap().as_slice());
/// }
/// ```
pub fn encode_config_slice<T: ?Sized + AsRef<[u8]>>(
input: &T,
config: Config,
output: &mut [u8],
) -> usize {
pub fn encode_config_slice<T: AsRef<[u8]>>(input: T, config: Config, output: &mut [u8]) -> usize {
let input_bytes = input.as_ref();

let encoded_size = encoded_size(input_bytes.len(), config)
Expand Down

0 comments on commit 61af8bc

Please sign in to comment.