Created
April 24, 2016 15:44
-
-
Save anonymous/b1354afa1220d057176ad3639cf12498 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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
struct Nat { val: u32} | |
impl Nat { | |
fn set(&mut self, x: u32) {self.val = x} | |
fn get(&self) -> u32 {self.val} | |
} | |
struct Pos { val: u32} | |
impl Pos { | |
fn set(&mut self, x: u32){self.val = x} | |
fn get(&self) -> u32 {self.val} | |
} | |
trait NatPos {} | |
impl NatPos for Nat{} | |
impl NatPos for Pos{} | |
fn main() { | |
let mut w = Nat {val:1}; | |
let mut x = &w as &NatPos; | |
// let z : Pos = &x; | |
// { | |
// let mut y : Nat : &x; | |
// y.set(0); | |
// } | |
// fprint("Positive integer: {}", z.get()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment