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

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

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:

1
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
2
3
4
5
6
7
8
[package]
name = "example"
version = "0.1.0"
edition = "2018"

[dependencies]
rocket = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev" }
rocket_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
2
3
4
5
6
7
8
9
10
11
12
13
[package]
name = "example"
version = "0.1.0"
edition = "2018"

[dependencies]
rocket = { git = "https://github.com/SergioBenitez/Rocket", version = "0.5.0-dev" }

[dependencies.rocket_contrib]
git = "https://github.com/SergioBenitez/Rocket"
version = "0.5.0-dev"
default-features = false
features = ["uuid"]

References

This post is licensed under CC BY 4.0 by the author.