Skip to content

Commit

Permalink
Merge pull request #7 from kevinheavey/tidying
Browse files Browse the repository at this point in the history
feature harmonisation and doc_auto_cfg
  • Loading branch information
kevinheavey authored Oct 13, 2024
2 parents 54ad40a + 5b1e7ea commit 4a832d6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
8 changes: 8 additions & 0 deletions crates/five8/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [0.2.1] - 2024-10-13

- Activate `std` feature of `five8_core` when `std` feature of `five8` is activated [(#7)](https://github.com/kevinheavey/five8/pull/7)

## [0.2.1] - 2024-10-13

- Add feature information to docs via `doc_auto_cfg` [(#7)](https://github.com/kevinheavey/five8/pull/7)

## [0.2.0] - 2024-09-05

- Remove the `len` parameter from `encode_32` and `encode_64`, and just return the `len`.
Expand Down
6 changes: 5 additions & 1 deletion crates/five8/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ keywords.workspace = true

[features]
dev-utils = [] # internal use only
std = []
std = ["five8_core/std"]

[dependencies]
five8_core.workspace = true
Expand All @@ -23,3 +23,7 @@ bs58 = "0.5.1"
five8 = { path = ".", features = ["std"] }
five8_const = { workspace = true }
proptest = "1.5.0"

[package.metadata.docs.rs]
features = ["std"]
rustdoc-args = ["--cfg=docsrs"]
10 changes: 5 additions & 5 deletions crates/five8/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,11 @@ mod tests {
let res2 = unsafe { _mm256_shuffle_epi32::<0b00_00_10_00>(core::mem::transmute(bytes2)) };
let out: [u32; 8] = unsafe { core::mem::transmute(res) };
let out2: [u32; 8] = unsafe { core::mem::transmute(res2) };
println!("out: {out:?}");
println!("out2: {out2:?}");
std::println!("out: {out:?}");
std::println!("out2: {out2:?}");
let unpacked = unsafe { _mm256_unpacklo_epi64(res, res2) };
let out3: [u32; 8] = unsafe { core::mem::transmute(unpacked) };
println!("out3: {out3:?}");
std::println!("out3: {out3:?}");
}

#[cfg(not(miri))]
Expand All @@ -477,7 +477,7 @@ mod tests {
fn proptest_decode_32(key in uniform32(0u8..)) {
let encoded = bs58::encode(key).into_vec();
let bs58_res = bs58::decode(&encoded).into_vec().unwrap();
let const_res = five8_const::decode_32_const(&String::from_utf8(encoded.clone()).unwrap());
let const_res = five8_const::decode_32_const(&std::string::String::from_utf8(encoded.clone()).unwrap());
let mut out = [0u8; 32];
decode_32(&encoded, &mut out).unwrap();
assert_eq!(bs58_res, out.to_vec());
Expand All @@ -494,7 +494,7 @@ mod tests {
combined[32..].copy_from_slice(&second_half);
let encoded = bs58::encode(combined).into_vec();
let bs58_res = bs58::decode(&encoded).into_vec().unwrap();
let const_res = five8_const::decode_64_const(&String::from_utf8(encoded.clone()).unwrap());
let const_res = five8_const::decode_64_const(&std::string::String::from_utf8(encoded.clone()).unwrap());
let mut out = [0u8; 64];
decode_64(&encoded, &mut out).unwrap();
assert_eq!(bs58_res, out.to_vec());
Expand Down
3 changes: 2 additions & 1 deletion crates/five8/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ fn u8s_to_u32s_swapped_64(bytes: &[u8; N_64], out: &mut [u8; N_64]) {
// 16, 17, 18, 19, 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3,
// )
// };
// println!("mask: {mask:?}");
// std::println!("mask: {mask:?}");
// let res_m256i =
// unsafe { core::arch::x86_64::_mm512_shuffle_epi8(core::mem::transmute(bytes), mask) };
// unsafe { core::mem::transmute(res_m256i) }
Expand Down Expand Up @@ -810,6 +810,7 @@ mod tests {
use prop::array::uniform32;
#[cfg(not(miri))]
use proptest::prelude::*;
use std::string::String;

use super::*;

Expand Down
5 changes: 4 additions & 1 deletion crates/five8/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![no_std]
#[cfg(feature = "std")]
extern crate std;
#[cfg(target_feature = "avx2")]
mod avx;

Expand Down
4 changes: 4 additions & 0 deletions crates/five8_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ keywords.workspace = true

[features]
std = []

[package.metadata.docs.rs]
features = ["std"]
rustdoc-args = ["--cfg=docsrs"]
21 changes: 12 additions & 9 deletions crates/five8_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
use core::fmt;
pub const BASE58_INVERSE_TABLE_OFFSET: u8 = b'1';
pub const BASE58_INVERSE_TABLE_SENTINEL: u8 = 1 + b'z' - BASE58_INVERSE_TABLE_OFFSET;

Expand Down Expand Up @@ -122,18 +127,16 @@ pub enum DecodeError {
impl std::error::Error for DecodeError {}

#[cfg(feature = "std")]
impl core::fmt::Display for DecodeError {
fn fmt(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DecodeError::InvalidChar(c) => {
::core::write!(formatter, "Illegal base58 char number: {}", c)
}
DecodeError::TooLong => formatter.write_str("Base58 string too long"),
DecodeError::TooShort => formatter.write_str("Base58 string too short"),
DecodeError::LargestTermTooHigh => {
formatter.write_str("Largest term greater than 2^32")
write!(f, "Illegal base58 char number: {}", c)
}
DecodeError::OutputTooLong => formatter.write_str("Decoded output has too many bytes"),
DecodeError::TooLong => f.write_str("Base58 string too long"),
DecodeError::TooShort => f.write_str("Base58 string too short"),
DecodeError::LargestTermTooHigh => f.write_str("Largest term greater than 2^32"),
DecodeError::OutputTooLong => f.write_str("Decoded output has too many bytes"),
}
}
}

0 comments on commit 4a832d6

Please sign in to comment.