Criticize the memorust

Here is my project on Github: GitHub - alimkoca/memorust: Simple and stupid flash card implementation in CLI

I want you to find unidiomatic code blocks in my code and criticize them. I can't ensure that the usage of the .clone() method is acceptable in iterations, loops, etc (memorust/memory_boxes.rs at master · alimkoca/memorust · GitHub).

The clone call is fine. Fundamentally, you're returning many strings, and each string that you return must be individually created somewhere.

That said, the way you're clearing the strings is poor. Do this instead:

box_list.push(vec![question.clone(), answer.clone()]);
question.clear();
answer.clear();

Otherwise, you're throwing away the allocation that the question variable owns on each iteration. It's better to reuse it.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.