I'm new to Rust and have written a small low level library called: hebrew_unicode_script.
I would like to receive feedback on the whole thing (set-up of the repository, documentation, test and the code itself) in order to improve.
I would remove is-even as a dependency. It's just a dev-dependency, but there's no need to add an external crate for that functionality. just % 2 == 0 or add your own private trait if you really like being able to do .is_even().
About the macro stuff. I did nor realize that is-even was a macro.
Writing a macro is somewhere at the end of my Rust learning todo list. Looking at is-even allthough it it only a few lines, it still seems a bit complicated for me now.
Yes, rust characters are a single unicode value (see the page you linked).
Is it more idiomatic? Maybe, I think it's debatable.
I personally think I prefer it better as a method because it matches the english grammar. The only way you can define methods on a char is by defining a trait.
I'm not usually a fan of when a crate I'm using has a trait I have to import. It's a bit annoying to have to remember the name of the trait, if it's different then the names of the methods you need to use.
The initial reason I thought of putting the methods on a trait is because in the code examples you were using a wildcard use statement to import all your functions. This is something that's convenient when writing code, but I think hurts readability in the long run. If you have many crates and modules all using wildcard imports you won't be able to easily read the code to determine the source of functions not defined in the file. (though easy with an editor configured to jump to definition)
Also:
pub fn is_apf_consonant(c: char) -> bool {
// An apf consonant can be any of the following:
// - an alternative consonant
// - a wide consonant
// - a consonant with a vowel
match c {
c if is_apf_consonant_alternative(c) => true,
c if is_apf_consonant_wide(c) => true,
c if is_apf_consonant_with_vowel(c) => true,
_ => false,
}
}
@richardscollin
Currently I am working on a program to search the Westminster Leningradus Codex.
At a point of time I had the idea of splitting the code in two parts: program specific and program a-specific.
The a-specific code could be outside my program as libs, so that others could be using those at well.
Meaning I am looking for the best/optimum usability of the library.
So far I have no experience in importing Traits.
Q. Why do you import Trait using "as _;"?
BTW Don't let my examples trick you. I just started coding in Rust!
PS
I will adapt the examples for readbility and modify the is_apf_consonant() when I'm home again
The underscore in the trait import isn't required you could also just say use crate_name::TraitName;
The difference is the one without the underscore will bring the symbol TraitName into scope and the one will only let you use the trait without bringing the name into scope.
It's useful to use the underscore if the trait name is the same across crates or modules.
An example of this would be: std::io::Write and std::fmt::Write or serde::Serialize and rkyv::Serialize.
You can use the same syntax to bind a different symbol to the trait when you import it such as: use std::fmt::Write as FmtWrite.
Now there is still the question of usage of this library.
I got the following ideas:
Idea 1
Would it be possible to have the functions and the trait version in one library?
I just read that code will not be compiled (using --release) if code is not used.
Idea 2
Why not have two versions of this crate?
v1.0.0 : v0.2.0 + improvements as discussed v2.0.0: all funcs behind a trait