mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-15 10:02:42 +00:00
37 lines
459 B
Rust
37 lines
459 B
Rust
// ./src/generics/impl.md
|
|
|
|
|
|
struct Val {
|
|
val: f64,
|
|
}
|
|
|
|
struct GenVal<T> {
|
|
gen_val: T,
|
|
}
|
|
|
|
// impl of Val
|
|
impl Val {
|
|
fn value(&self) -> &f64 {
|
|
&self.val
|
|
}
|
|
}
|
|
|
|
// impl of GenVal for a generic type `T`
|
|
impl<T> GenVal<T> {
|
|
fn value(&self) -> &T {
|
|
&self.gen_val
|
|
}
|
|
}
|
|
|
|
fn part0() {
|
|
let x = Val { val: 3.0 };
|
|
let y = GenVal { gen_val: 3i32 };
|
|
|
|
println!("{}, {}", x.value(), y.value());
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|