diff --git a/crates/five8/CHANGELOG.md b/crates/five8/CHANGELOG.md index 1419189..dcb4455 100644 --- a/crates/five8/CHANGELOG.md +++ b/crates/five8/CHANGELOG.md @@ -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`. diff --git a/crates/five8/Cargo.toml b/crates/five8/Cargo.toml index ea170b8..594e9ac 100644 --- a/crates/five8/Cargo.toml +++ b/crates/five8/Cargo.toml @@ -13,7 +13,7 @@ keywords.workspace = true [features] dev-utils = [] # internal use only -std = [] +std = ["five8_core/std"] [dependencies] five8_core.workspace = true @@ -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"] diff --git a/crates/five8/src/decode.rs b/crates/five8/src/decode.rs index bbf9193..f5aedd2 100644 --- a/crates/five8/src/decode.rs +++ b/crates/five8/src/decode.rs @@ -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))] @@ -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()); @@ -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()); diff --git a/crates/five8/src/encode.rs b/crates/five8/src/encode.rs index 9eb45a2..fd8eb57 100644 --- a/crates/five8/src/encode.rs +++ b/crates/five8/src/encode.rs @@ -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) } @@ -810,6 +810,7 @@ mod tests { use prop::array::uniform32; #[cfg(not(miri))] use proptest::prelude::*; + use std::string::String; use super::*; diff --git a/crates/five8/src/lib.rs b/crates/five8/src/lib.rs index 24d6f4d..cbee00b 100644 --- a/crates/five8/src/lib.rs +++ b/crates/five8/src/lib.rs @@ -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; diff --git a/crates/five8_core/Cargo.toml b/crates/five8_core/Cargo.toml index bd86d7e..3340b1b 100644 --- a/crates/five8_core/Cargo.toml +++ b/crates/five8_core/Cargo.toml @@ -13,3 +13,7 @@ keywords.workspace = true [features] std = [] + +[package.metadata.docs.rs] +features = ["std"] +rustdoc-args = ["--cfg=docsrs"] diff --git a/crates/five8_core/src/lib.rs b/crates/five8_core/src/lib.rs index 8e67ba4..9eb6f74 100644 --- a/crates/five8_core/src/lib.rs +++ b/crates/five8_core/src/lib.rs @@ -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; @@ -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"), } } }