Skip to content

Conversation

eupn
Copy link

@eupn eupn commented May 2, 2020

Implement Display instead of ToString for Mnemonic.

From ToString docs:

This trait is automatically implemented for any type which implements the Display trait. As such, ToString shouldn't be implemented directly: Display should be implemented instead, and you get the ToString implementation for free

Aside from a code being more idiomatic, the user will get the ability to use mnemonics in format! parameters:

let mnemonic = <...>;
format!("Write down your mnemonic words: {}", mnemonic);

self.0
impl Display for Mnemonic {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
let seed_stirng = self.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you try implement this without allocations? That should be quite straightforward. Just iterate over the words and write!( them one by one with a space in between.

Copy link
Author

Choose a reason for hiding this comment

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

Sure!

@eupn eupn closed this Dec 3, 2020
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