Re:Rewriting Libimagequant in Rust for Portability
by tialaramex on Tuesday January 04, 2022 @03:16PM
(#29799752)
Blanket implementation is a very common idea in Rust. The standard library "owns" its own Traits and so it gets to provide blanket implementations for those, but you can do the same for your own.
Here's (really, this is literally the code) how std provides a blanket implementation of Into given From:
impl<T, U> Into<U> for T
where
U: From<T>,
{
fn into(self) -> U {
U::from(self)
}
}
There's actually a chain, From implies Into, Into implies TryFrom, then TryFrom implies TryInto.
Here's (really, this is literally the code) how std provides a blanket implementation of Into given From:
There's actually a chain, From implies Into, Into implies TryFrom, then TryFrom implies TryInto.