Last active
March 6, 2017 18:05
-
-
Save Latrasis/a55170b4014b907c6fed93f86b2a5427 to your computer and use it in GitHub Desktop.
Newtype Support Concept
This file contains hidden or 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
// Type Alias Definition | |
type CharVec = Vec<char>; | |
// Impl Trait for Alias | |
impl ToString for CharVec { | |
fn to_string(&self) -> String { | |
String::from_iter(self) | |
} | |
} | |
fn foo<T: ToString>(bar: T) { | |
println!("My String {:}", bar.to_string()); | |
} | |
fn main() { | |
let sample = vec!['h','e','l','l','o']; | |
// Compiles | |
foo(sample as CharVec); | |
// Does not Compile | |
foo(sample); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment