From 60545a70da5fed0ae53a6ddc5ffc1d8a0e516d8c Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:15:12 +0400 Subject: [PATCH] rename five8_const fns --- crates/five8/src/decode.rs | 4 ++-- crates/five8_const/README.md | 6 +++--- crates/five8_const/src/lib.rs | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/five8/src/decode.rs b/crates/five8/src/decode.rs index 729bd6e..4a75dfe 100644 --- a/crates/five8/src/decode.rs +++ b/crates/five8/src/decode.rs @@ -473,7 +473,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_unwrap(&String::from_utf8(encoded.clone()).unwrap()); + let const_res = five8_const::decode_32_const(&String::from_utf8(encoded.clone()).unwrap()); let mut out = [0u8; 32]; decode_32(&encoded, &mut out).unwrap(); assert_eq!(bs58_res, out.to_vec()); @@ -489,7 +489,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_unwrap(&String::from_utf8(encoded.clone()).unwrap()); + let const_res = five8_const::decode_64_const(&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_const/README.md b/crates/five8_const/README.md index 8e7e898..a1edb17 100644 --- a/crates/five8_const/README.md +++ b/crates/five8_const/README.md @@ -3,16 +3,16 @@ This crate provides compile-time base58 decoding. It exposes four functions: +- `try_decode_32_const` +- `try_decode_64_const` - `decode_32_const` - `decode_64_const` -- `decode_32_const_unwrap` -- `decode_64_const_unwrap` While the first two functions return `Result` types, the `_unwrap` functions are more useful for declaring constants: ```rust -const EXAMPLE: [u8; 32] = five8_const::decode_32_const_unwrap("JEKNVnkbo3jma5nREBBJCDoXFVeKkD56V3xKrvRmWxFF"); +const EXAMPLE: [u8; 32] = five8_const::decode_32_const("JEKNVnkbo3jma5nREBBJCDoXFVeKkD56V3xKrvRmWxFF"); ``` If you want to base58 encoding or decoding at runtime, diff --git a/crates/five8_const/src/lib.rs b/crates/five8_const/src/lib.rs index caf1149..78f9c43 100644 --- a/crates/five8_const/src/lib.rs +++ b/crates/five8_const/src/lib.rs @@ -194,7 +194,7 @@ const fn decode_const_unwrap< } /// Try decode into a 32-byte array. -pub const fn decode_32_const(encoded: &str) -> Result<[u8; N_32], DecodeError> { +pub const fn try_decode_32_const(encoded: &str) -> Result<[u8; N_32], DecodeError> { decode_const::( encoded, &DEC_TABLE_32, @@ -202,7 +202,7 @@ pub const fn decode_32_const(encoded: &str) -> Result<[u8; N_32], DecodeError> { } /// Decode into a 32-byte array. Panic on error. -pub const fn decode_32_const_unwrap(encoded: &str) -> [u8; N_32] { +pub const fn decode_32_const(encoded: &str) -> [u8; N_32] { decode_const_unwrap::< N_32, BASE58_ENCODED_32_MAX_LEN, @@ -213,7 +213,7 @@ pub const fn decode_32_const_unwrap(encoded: &str) -> [u8; N_32] { } /// Try decode into a 64-byte array. -pub const fn decode_64_const(encoded: &str) -> Result<[u8; N_64], DecodeError> { +pub const fn try_decode_64_const(encoded: &str) -> Result<[u8; N_64], DecodeError> { decode_const::( encoded, &DEC_TABLE_64, @@ -221,7 +221,7 @@ pub const fn decode_64_const(encoded: &str) -> Result<[u8; N_64], DecodeError> { } /// Decode into a 64-byte array. Panic on error. -pub const fn decode_64_const_unwrap(encoded: &str) -> [u8; N_64] { +pub const fn decode_64_const(encoded: &str) -> [u8; N_64] { decode_const_unwrap::< N_64, BASE58_ENCODED_64_MAX_LEN, @@ -236,7 +236,7 @@ mod tests { use super::*; const DECODE_32_CONST_EXAMPLE: [u8; N_32] = - decode_32_const_unwrap("JEKNVnkbo3jma5nREBBJCDoXFVeKkD56V3xKrvRmWxFF"); + decode_32_const("JEKNVnkbo3jma5nREBBJCDoXFVeKkD56V3xKrvRmWxFF"); #[test] fn test_decode_const_ok() { @@ -248,13 +248,13 @@ mod tests { #[test] #[should_panic] fn test_decode_const_small_buffer_panic() { - decode_32_const_unwrap("a3gV"); + decode_32_const("a3gV"); } #[test] #[should_panic] fn test_decode_const_invalid_char_panic() { let sample = "123456789abcd!efghij"; - decode_32_const_unwrap(sample); + decode_32_const(sample); } }