Guest User

Untitled

a guest
May 27th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. trait Fromable {
  2. fn create() -> Self;
  3. }
  4.  
  5. struct A;
  6.  
  7. impl Fromable for A {
  8. fn create() -> Self {
  9. A {}
  10. }
  11. }
  12.  
  13. fn construct<T: Fromable>() -> impl Fromable {
  14. T::create()
  15. }
  16.  
  17. fn main() {
  18. let s = "'A";
  19.  
  20. match s {
  21. "'A" => Some(construct::<A>()),
  22. _ => None
  23. };
  24. }
Add Comment
Please, Sign In to add comment