blob: 59cf183b9b107104c819f0ec0f6620dfa141c301 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#[macro_use]
extern crate rental;
#[derive(Debug)]
pub struct Foo {
i: i32,
}
rental! {
mod rentals {
use super::*;
#[rental(debug, deref_suffix)]
pub struct SimpleRef {
foo: Box<Foo>,
iref: &'foo i32,
}
#[rental_mut(debug, deref_suffix)]
pub struct SimpleMut {
foo: Box<Foo>,
iref: &'foo mut i32,
}
}
}
#[test]
fn print() {
let foo = Foo { i: 5 };
let sr = rentals::SimpleRef::new(Box::new(foo), |foo| &foo.i);
println!("{:?}", sr);
let foo = Foo { i: 5 };
let sm = rentals::SimpleMut::new(Box::new(foo), |foo| &mut foo.i);
println!("{:?}", sm);
}
|