blob: 545c2714aebd1cdb51d0365f7899e6b8521f647d (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#[macro_use]
extern crate rental;
//use std::marker::PhantomData;
pub struct Foo {
i: i32,
}
//pub struct Invariant<'a> {
// iref: &'a i32,
// inv: PhantomData<&'a mut &'a ()>,
//}
rental! {
mod rentals {
use super::*;
#[rental(covariant)]
pub struct SimpleRef {
foo: Box<Foo>,
iref: &'foo i32,
}
#[rental_mut(covariant)]
pub struct SimpleMut {
foo: Box<Foo>,
iref: &'foo mut i32,
}
// #[rental(covariant)]
// pub struct ShouldBreak {
// foo: Box<Foo>,
// inv: Invariant<'foo>,
// }
}
}
#[test]
fn borrow() {
let foo = Foo { i: 5 };
let fr = rentals::SimpleRef::new(Box::new(foo), |foo| &foo.i);
let b = fr.all();
assert_eq!(**b.iref, 5);
}
|