Skip to content

Instantly share code, notes, and snippets.

@cowboy-bebug
Created October 11, 2019 02:25
Show Gist options
  • Select an option

  • Save cowboy-bebug/6b6d492a31e5e8a34bdef6ec0d78da18 to your computer and use it in GitHub Desktop.

Select an option

Save cowboy-bebug/6b6d492a31e5e8a34bdef6ec0d78da18 to your computer and use it in GitHub Desktop.
specialization usage to impl a fn with default return values & "override" it for certain types
#![feature(specialization)]
trait Foo {
fn foo(&self);
}
impl<T> Foo for T {
default fn foo(&self) { println!("default foo") }
}
struct SpecialType;
impl Foo for SpecialType {
fn foo(&self) { println!("foo for SpecialType") }
}
fn main() {
42_u32.foo();
SpecialType.foo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment