https://github.com/viperproject/rust-contracts
https://github.com/viperproject/rust-contracts
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/viperproject/rust-contracts
- Owner: viperproject
- License: apache-2.0
- Created: 2019-07-30T15:47:25.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-14T08:15:26.000Z (over 4 years ago)
- Last Synced: 2023-03-23T02:05:45.281Z (about 3 years ago)
- Language: Rust
- Size: 29.3 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Rust Contracts (Deprecated)
===========================
**This project is not actively maintained. If you want something that is maintained, please see Prusti and its contracts library: https://github.com/viperproject/prusti-dev**
[](https://travis-ci.org/viperproject/rust-contracts)
This crate offers the syntax to specify the *contract* of Rust functions (e.g. functional specification).
By default all contracts are ignored.
Verification tools can plug-in their implementation of contracts, in order to check the contracts statically or at runtime, using the technique of their choice.
Example of contract
-------------------
Contracts can be used to specify the requirements and the guarantees of a function:
```rust
#[requires(x > 5)]
#[ensures(result >= 0)]
fn foo(x: i32) -> i32 {
if x <= 5 {
panic!();
}
(x - 1) / 2
}
```
Compile ignoring contracts
--------------------------
Be default, contracts are ignored.
```bash
cargo run --example true
```
Note that the example does not print messages to standard output.
Custom implementation of contracts
----------------------------------
The behaviour of contracts can be configured.
As an example, we provide in the `example_verification_tool` and `example_contracts_impl` folders an implementation that prints the contracts at runtime.
```bash
# Build the implementation of contracts and the compilation tool
cargo build --manifest-path example_contracts_impl/Cargo.toml
cargo build --manifest-path example_verification_tool/Cargo.toml
# Compile and run an example with the modified contracts behaviour
export RUST_CONTRACTS_LIB=example_contracts_impl/target/debug/libexample_contracts_impl.so
cargo clean
example_verification_tool/target/debug/cargo-tool run --example true
```
You can see from the output that the contract is printed while running the example.
License
-------
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.