thacoon's Blog

Rocket (Rust) - Trait is not implemented compilation error for a type that it has implemented

· thacoon

The problem

I needed to use the 0.5.0-dev version of Rocket as I wanted to use the new async features. As this version is not yet published you need to point Cargo to a git repository. However, I needed some functionality of rocket_contrib, the Uuuid, but I was very confused on how to add it to the dependencies correctly. As I am currently very new on Rust, Rocket and the documentation did not properly explained it. I got the following error when compiling:

the trait `FromFormField<'_>` is not implemented for `rocket_contrib::uuid::Uuid`

At this point I was very confused as Uuid implements the FromFormField according to the docs. But the problem was that I did not properly configured my Cargo.toml

The solution

The correct Cargo.toml would be the following

1[package]
2name = "example"
3version = "0.1.0"
4edition = "2018"
5
6[dependencies]
7rocket = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev" }
8rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev", default-features = false, features = ["uuid"] }

Or the following would also be correct

 1[package]
 2name = "example"
 3version = "0.1.0"
 4edition = "2018"
 5
 6[dependencies]
 7rocket = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev" }
 8
 9[dependencies.rocket_contrib]
10git = "https://github.com/SergioBenitez/Rocket"
11version = "0.5.0-dev"
12default-features = false
13features = ["uuid"]

References

#rust #rocket

Reply to this post by email ↪