I'm new to Rust, and a bit confused about the usage of generic types.
Consider the below scenario:
I can create a Date type like so:
use chrono::prelude::*;
fn main() {
let date = Utc.ymd(2021, 1, 1);
}
Now if I create a function foo to do something similar:
use chrono::prelude::*;
fn foo<Tz: TimeZone>(date: Date<Tz>) {
let other_date = Tz.ymd(2020, 1, 1);
}
fn main() {
let date = Utc.ymd(2021, 1, 1);
foo(date);
}
I expected Tz to be substituted by Utc, and Tz.ymd to be equivalent to Utc.ymd, but it's not so:
error[E0423]: expected value, found type parameter `Tz`
--> src/main.rs:4:20
|
4 | let other_date = Tz.ymd(2020, 1, 1);
| ^^ not a value
Which makes me think it needs to be instantiated first? But how come that wasn't needed in the first place? What am I misunderstanding here?