Unable to use chrono feature with diesel in Rust/Actix application

691 views Asked by At

I am still quite a rookie on Rust.

I try to use NaiveDateTime in some of my diesel models.

Therefore I try to import chrono as an extern crate like this:

src/db/models.rs

extern crate diesel;
extern crate chrono;

use diesel::{sql_types};
use chrono;

// model implementations follow below ...

However I am getting a rust error saying:

can't find crate for `chrono`: can't find crate

chrono is declared as a diesel feature. My Cargo.toml looks like this:

[package]
name = "backend"
version = "0.1.0"
authors = ["My Name <[email protected]>"]
edition = "2018"

[dependencies]
actix-web="3"
diesel= { version = "1.4.5", features = ["mysql", "chrono"] }
dotenv= { version = "0.15.0" }

[[bin]]
name = "main"
path = "src/main.rs"

What am I doing wrong here?

1

There are 1 answers

4
justinas On BEST ANSWER

You need to install chrono itself.

[dependencies]
actix-web = "3"
chrono = "0.4"
diesel = { version = "1.4.5", features = ["mysql", "chrono"] }
dotenv = { version = "0.15.0" }

Adding a chrono feature to diesel only makes diesel compile with a dependency on chrono and glue code to integrate it. However, to use chrono in your own crate, you still have to declare it in Cargo.toml.