Skip to content

Conversation

@stevenroose
Copy link
Collaborator

Based on comments from @sgeisler in #6.

Copy link

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, only left some minor nits.


match iter.next() {
// If all languages were eliminated, it's an invalid word.
None => return Err(Error::UnknownWord(idx)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, please don't change it unless you deem it important yourself: technically it doesn't have to be the current word that was "invalid", it could have been any word before that, that happened to exclude some language that was actually meant. The common case is "this is an invalid word" though, so it makes a lot of sense to not overcomplicate it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I agree that this is the best way to return it though. Majority of cases an accidental invalid word will not by chance be valid in a random wrong language 😅

Cargo.toml Outdated
[features]
default = [ "std" ]
std = [ "serde/std" ]
core = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason ever not to have core available? Does feature gating it make any sense? That feels like saying "oh, we might be missing basic arithmetic on some platforms" 😆.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah true, core is always there, my bad, I was confused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a fix

/// Generate a new [Mnemonic] in the given language.
/// For the different supported word counts, see documentation on [Mnemonic].
#[cfg(feature = "rand")]
pub fn generate_in(language: Language, word_count: usize) -> Result<Mnemonic, Error> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should stay in here for convenience or should be thrown out for increased focus …. If SemVer is a concern: maybe it can be deprecated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh I think it's ok. I like that you don't have to fiddle with rand to use this.

@sgeisler
Copy link

Awesome, LGTM!

#[cfg(feature = "rand")]
#[test]
fn test_generate() {
let _ = Mnemonic::generate(24).unwrap();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these could be doctests, so that they are also improving docs (not everyone might be aware of rand_core's relation to rand)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otoh, only one of these is really interesting …

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point :D will do

@stevenroose stevenroose force-pushed the sebas-comments branch 2 times, most recently from 82b9914 to e990720 Compare March 24, 2021 19:20
@stevenroose
Copy link
Collaborator Author

I consider that LGTM + nit as an ack 😅

@stevenroose stevenroose merged commit 1786f61 into master Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants