DEV Community

loading...

Discussion on: Rocket Tutorial 03: Proper routing

Collapse
sentinel1909 profile image
Jeff Mitchell

I want to thank you for this tutorial, it's so excellent. I'm having a little trouble with a block of code in the User implementation block of db.rs. I've uploaded a screenshot. The .collect(); part of the new function that takes a new user seems to be problematic. The compiler throws an error. .collect(); -> value of type std::string::String cannot be built from std::iter::Iterator<Item-u8> I've checked what I typed against your code on github and all seems to be in order...I'm a bit stumped.

This reminds me of a time back in University in my engineering graphics class...was doing a program for a project and had a missing comma in the code that I couldn't see...prof spotted it in about 60 seconds :)

Collapse
davidedelpapa profile image
Davide Del Papa Author

Hi. Sorry, where's the screenshot?
Anyway, I have to check the code on the latest rocket release.. It might be a version compatibility issue. So check also the rocket version and the dependencies versions (the .lock file might help)

Collapse
sentinel1909 profile image
Jeff Mitchell

I don't think the screenshot quite worked. I checked my post afterwards and couldn't see it either. I did find a solution such that the code compiles and output is as expected. I'm not at my home computer now, but will post later.

Collapse
sentinel1909 profile image
Jeff Mitchell

I modified the impl User block by adding .map(char::from) just before .collect(), everything compiled and I was able to carry on with the testing described in the rest of Tutorial 3. Here's the code:

impl User {
pub fn new(name: String, email: String, password: String) -> Self {
let salt: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(20)
.map(char::from)
.collect();
let hashed_password = hash_password(&password, &salt);

I'll be honest, I Googled for this...I'm now researching to understand why this worked :)

Thread Thread
davidedelpapa profile image
Davide Del Papa Author

Up till version 0.7.3, rng.sample(Alphanumeric)) would produce chars. After 0.8.0 you need the char conversion you added to the code.