I am working with the chrono
library, and do not know how to define a struct field that is a vector of DateTime<Tz: TimeZone>
structs with a TimeZone
trait instead of a concrete type.
I.e, I can do:
use chrono::{DateTime, TimeZone, Utc}; // 0.4.11
pub struct ItemSchedule {
pub times: Vec<Box<DateTime<Utc>>>,
}
When I try to use a trait object:
use chrono::{DateTime, TimeZone, Utc}; // 0.4.11
pub struct ItemSchedule {
pub times: Vec<Box<DateTime<dyn TimeZone>>>,
}
I get an error:
error[E0191]: the value of the associated type `Offset` (from trait `chrono::offset::TimeZone`) must be specified
--> src/lib.rs:4:37
|
4 | pub times: Vec<Box<DateTime<dyn TimeZone>>>,
| ^^^^^^^^ help: specify the associated type: `TimeZone<Offset = Type>`
Looking at the code, the TimeZone
trait has an associated type called Offset
, which has to implement a trait called Offset
. I also get errors if I attempt to specify this the type declaration.