-
Notifications
You must be signed in to change notification settings - Fork 1
sdk%refac: consolidate exports, types, add utf8 serde codec to process domain names, preserve unknown values, drop legacy macro
#11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8b61d79
890842e
9dee8f6
4d12741
9ca0dbe
657c4c2
4c2663f
ae9b388
2e29b9c
1db131b
228e54c
d38a8be
cebf56e
9545bc4
eb95de4
849f2f4
f99f939
d3fdcd4
e8cb144
5fcd8cb
5a50bf4
ed05c41
65cd62c
3a8ff96
674dfbc
9d5ccc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| rules: | ||
| - id: no-newtype-in-types | ||
| message: "do not define newtypes in dash-types; use the owning crate instead" | ||
| severity: ERROR | ||
| languages: [rust] | ||
| paths: | ||
| include: [/pkgs/types/src/**/*.rs] | ||
| exclude: [/pkgs/types/src/hex.rs, /pkgs/types/src/uint.rs] | ||
| pattern-regex: '\b(?:make|impl)_(?:bytes|num|type)!\s*\{' |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,14 +6,40 @@ | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| //! Fixed-size opaque hash blob types. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| use crate::ParseHexError; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| use core::fmt; | ||||||||||||||||||||||||||||||||||||||
| use core::hash::Hash; | ||||||||||||||||||||||||||||||||||||||
| use core::str::FromStr; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| pub(crate) const HEX_LOWER: [u8; 16] = *b"0123456789abcdef"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /// Error returned when parsing a hex string fails. | ||||||||||||||||||||||||||||||||||||||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||||||||||||||||||||||||||||||||||||||
| pub enum ParseHexError { | ||||||||||||||||||||||||||||||||||||||
| /// The hex string has an odd number of characters. | ||||||||||||||||||||||||||||||||||||||
| OddLength, | ||||||||||||||||||||||||||||||||||||||
| /// The decoded byte count does not match the expected length. | ||||||||||||||||||||||||||||||||||||||
| InvalidLength { expected: usize, got: usize }, | ||||||||||||||||||||||||||||||||||||||
| /// A non-hex character was encountered. | ||||||||||||||||||||||||||||||||||||||
| InvalidChar(u8), | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Add This enum currently derives Proposed patch-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ParseHexError {As per coding guidelines: "Derive 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| impl fmt::Display for ParseHexError { | ||||||||||||||||||||||||||||||||||||||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||||||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||||||||||
| Self::OddLength => write!(f, "hex string has odd length"), | ||||||||||||||||||||||||||||||||||||||
| Self::InvalidLength { expected, got } => { | ||||||||||||||||||||||||||||||||||||||
| write!(f, "expected {expected} hex chars, got {got}") | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| Self::InvalidChar(c) => { | ||||||||||||||||||||||||||||||||||||||
| write!(f, "invalid hex character: {:#04x}", c) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #[cfg(feature = "std")] | ||||||||||||||||||||||||||||||||||||||
| impl std::error::Error for ParseHexError {} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| pub(crate) fn hex_val(c: u8) -> Result<u8, ParseHexError> { | ||||||||||||||||||||||||||||||||||||||
| match c { | ||||||||||||||||||||||||||||||||||||||
| b'0'..=b'9' => Ok(c - b'0'), | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.