-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathtraits.rs
78 lines (62 loc) · 1.21 KB
/
traits.rs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#[allow(unused_imports)]
use builtin::*;
use builtin_macros::*;
use vstd::{modes::*, pervasive::*, prelude::*, seq::*};
verus! {
trait T<A> {
spec fn req(&self, a: A) -> bool;
spec fn ens(&self, a: A, r: A) -> bool;
fn f(&self, a: &A) -> (ra: A)
requires
self.req(*a),
ensures
self.ens(*a, ra),
;
}
struct B {
x: bool,
}
struct I {
x: u64,
}
impl T<bool> for B {
spec fn req(&self, a: bool) -> bool {
a
}
spec fn ens(&self, a: bool, r: bool) -> bool {
r == (a && self.x)
}
fn f(&self, a: &bool) -> bool {
*a && self.x
}
}
impl T<u64> for I {
spec fn req(&self, a: u64) -> bool {
self.x < a && a < 100
}
spec fn ens(&self, a: u64, r: u64) -> bool {
self.x <= r && r < 100
}
fn f(&self, a: &u64) -> u64 {
self.x / 2 + a / 2
}
}
fn p<A, Z: T<A>>(a: &A, z: &Z) -> (rz: A)
requires
z.req(*a),
ensures
z.ens(*a, rz),
{
z.f(a)
}
fn test() -> bool {
let i = I { x: 30 };
print_u64(p(&70, &i));
let b = B { x: false };
b.f(&true) && p(&true, &b)
}
#[verifier::external_body]
fn main() {
println!("{}", test());
}
} // verus!