Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused)]
- use std::rc::Rc;
- use std::path::PathBuf;
- trait HasNew {
- fn new() -> Self;
- fn x(&self) -> Self;
- fn y(&self) -> Vec<Rc<Self>> where Self : Sized;
- }
- pub trait TreeNode
- {
- fn children(&self) -> Rc<Self>;
- }
- struct X {
- x : u16
- }
- impl X {
- fn new() -> Self {
- X { x : 8 }
- }
- }
- impl TreeNode for X {
- fn children(&self) -> Rc<Self> {
- Rc::new(X::new())
- }
- }
- impl HasNew for u16{
- fn new() -> u16 {
- return 16;
- }
- fn x(&self) -> u16 {
- 2 + 2
- }
- fn y(&self) -> Vec<Rc<u16>> {
- vec![Rc::new(2)]
- }
- }
- fn returns_t<T: HasNew>() -> T {
- return T::new();
- }
- fn main() {
- let u: u16 = returns_t();
- let t : Rc<TreeNode> = X::new().children();
- println!("u={}", u);
- }
Add Comment
Please, Sign In to add comment