I was looking over some Rust examples, and found something interesting:

https://github.com/serde-rs/serde

let deserialized: Point = serde_json::from_str(&serialized).unwrap();

from_str is defined as:

pub fn from_str<'a, T>(s: &'a str) -> Result<T>

From what I understand, the function infers the template type from the expected return type. Is it possible to achieve something like that in D?

I tried something like:

T returnDefault(T)()
{
    return T.init;
}

int i = returnDefault();

but it doesn't work.

int i = returnDefault!int(); obviously works, but the point is I would like to skip the explicit type.

Reply via email to