This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example of implementing a method that accepts closures with different input arguments. | |
// The trick to avoid Rust complaining about conflicting implementations is to specify | |
// the arguments for each specialization in a separate type parameter. | |
// See https://geo-ant.github.io/blog/2021/rust-traits-and-variadic-functions/ | |
fn main() { | |
let mut foo = Foo::default(); | |
foo.add_fn(|| 0); | |
foo.add_fn(|a| a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ...from 'Inheritance Is The Base Class of Evil' | |
use std::fmt; | |
use std::rc::Rc; | |
fn white_space(count: usize) -> String { | |
std::iter::repeat(' ').take(count).collect::<String>() | |
} | |
trait Drawable { |