-
Notifications
You must be signed in to change notification settings - Fork 0
Change error handling and update comments for cargo doc #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,25 +3,17 @@ use crate::{ | |
| CollapsedEnsNameToken, EnsNameToken, TokenDisallowed, TokenEmoji, TokenIgnored, | ||
| TokenMapped, TokenNfc, TokenStop, TokenValid, | ||
| }, | ||
| utils, CodePoint, CodePointsSpecs, ProcessError, | ||
| utils, CodePoint, CodePointsSpecs, | ||
| }; | ||
|
|
||
| /// Represents a full ENS name, including the original input and the sequence of tokens | ||
| /// vitalik.eth | ||
| /// ^^^^^^^^^^^ | ||
| /// name | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct TokenizedName { | ||
| pub input: String, | ||
| pub tokens: Vec<EnsNameToken>, | ||
| } | ||
|
|
||
| /// Represents a tokenized ENS label (part of a name separated by periods), including sequence of tokens | ||
| /// vitalik.eth | ||
| /// ^^^^^^^ | ||
| /// label 1 | ||
| /// ^^^ | ||
| /// label 2 | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct TokenizedLabel<'a> { | ||
| pub tokens: &'a [EnsNameToken], | ||
|
|
@@ -36,11 +28,7 @@ impl TokenizedName { | |
| } | ||
|
|
||
| /// Tokenizes an input string, applying NFC normalization if requested. | ||
| pub fn from_input( | ||
| input: impl AsRef<str>, | ||
| specs: &CodePointsSpecs, | ||
| apply_nfc: bool, | ||
| ) -> Result<Self, ProcessError> { | ||
| pub fn from_input(input: impl AsRef<str>, specs: &CodePointsSpecs, apply_nfc: bool) -> Self { | ||
|
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. Reconsider removing error handling from Changing |
||
| tokenize_name(input, specs, apply_nfc) | ||
| } | ||
|
|
||
|
|
@@ -143,27 +131,23 @@ where | |
| } | ||
| } | ||
|
|
||
| fn tokenize_name( | ||
| name: impl AsRef<str>, | ||
| specs: &CodePointsSpecs, | ||
| apply_nfc: bool, | ||
| ) -> Result<TokenizedName, ProcessError> { | ||
| fn tokenize_name(name: impl AsRef<str>, specs: &CodePointsSpecs, apply_nfc: bool) -> TokenizedName { | ||
| let name = name.as_ref(); | ||
| if name.is_empty() { | ||
| return Ok(TokenizedName::empty()); | ||
| return TokenizedName::empty(); | ||
| } | ||
| let tokens = tokenize_input(name, specs, apply_nfc)?; | ||
| Ok(TokenizedName { | ||
| let tokens = tokenize_input(name, specs, apply_nfc); | ||
| TokenizedName { | ||
| input: name.to_string(), | ||
| tokens, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn tokenize_input( | ||
| input: impl AsRef<str>, | ||
| specs: &CodePointsSpecs, | ||
| apply_nfc: bool, | ||
| ) -> Result<Vec<EnsNameToken>, ProcessError> { | ||
| ) -> Vec<EnsNameToken> { | ||
| let input = input.as_ref(); | ||
| let emojis = specs.finditer_emoji(input).collect::<Vec<_>>(); | ||
|
|
||
|
|
@@ -192,7 +176,7 @@ fn tokenize_input( | |
| perform_nfc_transform(&mut tokens, specs); | ||
| } | ||
| collapse_valid_tokens(&mut tokens); | ||
| Ok(tokens) | ||
| tokens | ||
| } | ||
|
|
||
| fn perform_nfc_transform(tokens: &mut Vec<EnsNameToken>, specs: &CodePointsSpecs) { | ||
|
|
@@ -470,7 +454,7 @@ mod tests { | |
| #[case] expected: Vec<EnsNameToken>, | ||
| specs: &CodePointsSpecs, | ||
| ) { | ||
| let tokens = tokenize_input(input, specs, apply_nfc).expect("tokenize"); | ||
| let tokens = tokenize_input(input, specs, apply_nfc); | ||
| assert_eq!(tokens, expected); | ||
| } | ||
|
|
||
|
|
@@ -494,7 +478,7 @@ mod tests { | |
| #[case] expected: Vec<CollapsedEnsNameToken>, | ||
| specs: &CodePointsSpecs, | ||
| ) { | ||
| let tokens = tokenize_input(input, specs, true).expect("tokenize"); | ||
| let tokens = tokenize_input(input, specs, true); | ||
| let label = TokenizedLabel::from(&tokens); | ||
| let result = label.collapse_into_text_or_emoji(); | ||
| assert_eq!(result, expected); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing visibility to
pub(crate)may impact external usersModifying
pub use code_points::*;topub(crate) use code_points::*;restricts the visibility ofcode_pointsexports to within the crate. If any external code depends on these exports, this change can introduce breaking changes. Please verify that no public APIs are affected or consider deprecating before removal.