vstd_extra/
resource_invariant.rs1#[cfg(feature = "irc11")]
3use vstd::thread_view::Objective;
4use vstd::{prelude::*, resource};
5
6verus! {
7
8pub trait ResourceInvariant<V> {
10 type Constant;
12
13 #[cfg(not(feature = "irc11"))]
15 type Resource;
16
17 #[cfg(feature = "irc11")]
22 type Resource: Objective;
23
24 spec fn inv(constant: Self::Constant, value: V, resource: Self::Resource) -> bool;
26}
27
28pub trait SimpleResourceInvariant<V> {
30 #[cfg(not(feature = "irc11"))]
32 type Resource;
33
34 #[cfg(feature = "irc11")]
39 type Resource: Objective;
40
41 spec fn inv(value: V, resource: Self::Resource) -> bool;
43}
44
45impl<V, T: SimpleResourceInvariant<V>> ResourceInvariant<V> for T {
46 type Constant = ();
47
48 type Resource = <T as SimpleResourceInvariant<V>>::Resource;
49
50 open spec fn inv(_constant: (), value: V, resource: Self::Resource) -> bool {
51 <T as SimpleResourceInvariant<V>>::inv(value, resource)
52 }
53}
54
55pub trait ValueInvariant<V> {
57 spec fn inv(value: V) -> bool;
59}
60
61impl<V, T: ValueInvariant<V>> SimpleResourceInvariant<V> for T {
62 type Resource = ();
63
64 open spec fn inv(value: V, _resource: ()) -> bool {
65 <T as ValueInvariant<V>>::inv(value)
66 }
67}
68
69pub struct TrivialResourceInvariant;
71
72impl<V> ValueInvariant<V> for TrivialResourceInvariant {
73 open spec fn inv(value: V) -> bool {
74 true
75 }
76}
77
78}