4 ms·
> 2.days().from_now() > > says that we are performing the action 'days' on the object '2'. What could that possibly do? It does what the language definition s
by pcwalton 13y ago
> 2.days().from_now()
>
> says that we are performing the action 'days' on the object '2'. What could that possibly do?
It does what the language definition says it does: it tells the compiler to search through traits that were explicitly imported to find a method called "days" and calls that. (Since "int" is a built-in type, it has no methods except for those provided via traits that were imported, so traits are the only potential source of these methods.) If there is more than one matching method, Rust never guesses: it instead signals an error.
> I don't mind 'fluent' style interfaces as long as they don't mess up the normal meanings of what objects and methods are, but sadly they usually do.
In this case they don't. It falls out of what traits and methods already provide in Rust.