You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
600 B

struct D {
a: u32,
b: u32
}
impl D {
pub fn from(a: u32, b: u32) -> D {
D { a: a, b: b }
}
pub fn print(&self) {
println!("{}/{}", self.a, self.b);
}
pub fn add_n(&self, n: u32) -> D {
let aa = self.b;
return D::from(aa + self.a, self.b);
}
pub fn iter(&self) -> D {
let mut res = self.add_n(1);
let dd = D::from(res.b, res.a);
return dd.add_n(1);
}
}
fn main() {
let mut d = D::from(1, 2);
d = d.add_n(1);
d.print();
for n in 0..100 {
d = d.iter();
d.print();
}
}