Rustcast #6 - traits From and Into in Rust programming language

preview_player
Показать описание
This tutorial explains traits From and Into, which are widely used for data type conversion in Rust.
They may be considered as an alternative to method overriding (that does not exist in Rust), which
allows you defined user friendly generic functions, that can work with different data types.

In the video you will also find a little coding session with an example.

BOOKS:

CONTENT:
* Introduction of From and Into traits
* Taking a look at implementations of From trait in the standard library
* Coding session with an example how From and Into traits can be used in order to build a better function API.

LINKS:

This video was produced with the following open source software:
Рекомендации по теме
Комментарии
Автор

Works great for me. Thanks Sergey for a detailed explanation!

veciolupo
Автор

Wow I had no idea about f64: From<TA> + From<TB> syntax! It's like there's a prolog interpreter inside the type system!

eignnx_
Автор

Wonderful video! Thank you for showing the last part; I saw the + operator being used in source code using From and it boggled my mind! Not anymore!

meuko
Автор

Would be nice if you explained how to implement your own from and into

Renni-kgvf
Автор

Great job at making these video's man!

WindBringsMemories
Автор

Hi, It was inspiring all this:

pub fn add(a: impl Into<f64>, b: impl Into<f64>) -> f64 {
a.into() + b.into()
}
[...]
pub fn add<TS: Add>(a: impl Into<TS>, b: impl Into<TS>) -> <TS as std::ops::Add>::Output {
a.into() + b.into()
}
[...]
pub fn add<TS: Add>(a: impl Into<TS>, b: impl Into<TS>) -> TS::Output {
a.into() + b.into()
}

jlovas