| Crates.io | ephapax-proven |
| lib.rs | ephapax-proven |
| version | 0.1.0 |
| created_at | 2026-01-24 08:11:19.07084+00 |
| updated_at | 2026-01-24 08:11:19.07084+00 |
| description | Safe Rust wrappers for formally verified Proven library via pure Zig FFI |
| homepage | |
| repository | https://github.com/hyperpolymath/ephapax-proven |
| max_upload_size | |
| id | 2066385 |
| size | 143,407 |
= ephapax-proven :toc: :toc-placement!:
Safe Rust wrappers for formally verified Proven library
Ergonomic, safe Rust APIs over the formally verified Idris2 Proven library, providing RAII memory management and linear type semantics.
toc::[]
== Overview
This crate provides safe, idiomatic Rust wrappers around the unsafe FFI bindings in ephapax-proven-sys. All memory management is automatic via RAII (Drop trait), and Rust's ownership system enforces linear/affine type semantics.
=== Features
=== Modules
[cols="1,2,2"] |=== |Module |Type |Description
|lru
|LruCache
|LRU cache with capacity guarantees (size ≤ capacity proven)
|buffer
|Buffer
|Bounds-checked buffer (no overflow, formally verified)
|resource
|ResourceHandle, ResourceGuard
|Resource lifecycle tracking (no leaks, correct acquire/release)
|===
== Installation
Add to your Cargo.toml:
=== Requirements
ephapax-proven-sys (automatically pulled in)libephapax_proven.so from https://github.com/hyperpolymath/ephapax-proven-ffi[ephapax-proven-ffi]== Usage
=== LRU Cache
use ephapax_proven::lru::LruCache;
fn main() -> Result<(), Box
// Insert key-value pairs
cache.put(b"user:123", b"Alice")?;
cache.put(b"user:456", b"Bob")?;
// Retrieve values
if let Some(name) = cache.get(b"user:123") {
println!("Found: {:?}", name); // "Alice"
}
// Check size and capacity
println!("Size: {}", cache.size()); // 2
println!("Full: {}", cache.is_full()); // false
Ok(())
=== Buffer
use ephapax_proven::buffer::Buffer;
fn main() -> Result<(), Box
// Write data
buf.write(b"Hello, ")?;
buf.write(b"formal verification!")?;
// Read data
let mut output = vec![0u8; 5];
buf.read(0, &mut output)?;
assert_eq!(&output, b"Hello");
println!("Size: {}", buf.size()); // 27
println!("Remaining: {}", buf.remaining()); // 997
Ok(())
=== Resource Handle
use ephapax_proven::resource::{ResourceHandle, ResourceGuard};
fn main() -> Result<(), Box
// Manual acquire/release
handle.acquire()?;
println!("Held: {}", handle.is_held()); // true
handle.release()?;
// Or use RAII guard for automatic release
{
let _guard = ResourceGuard::new(&mut handle)?;
println!("Acquired via guard");
// ... use resource ...
} // Automatically released here
Ok(())
== Linear Type Semantics
All types in this crate are !Copy and !Clone, enforcing linear usage:
This prevents:
== Error Handling
All operations return Result<T, Error>:
use ephapax_proven::{Error, buffer::Buffer};
let mut buf = Buffer::new(5)?; buf.write(b"12345")?;
Error variants:
AllocationFailed - Out of memoryBufferFull - No space for writeOutOfBounds - Read/write out of boundsInvalidOperation - Invalid state transitionNullPointer - FFI returned null (corruption)== Safety
This crate is 100% safe Rust - no unsafe blocks exposed to users. All unsafe FFI calls are encapsulated in the safe wrappers with proper error handling.
The underlying Proven library provides formal verification that:
== Thread Safety
Types in this crate are not Send or Sync because the underlying C library uses a global allocator without synchronization. For thread-safe usage, wrap in Arc<Mutex<T>> or use per-thread instances.
== Examples
See the examples/ directory for more usage patterns:
lru_cache.rs - Complete LRU cache usagebuffer_io.rs - Buffer read/write patternsresource_guard.rs - RAII resource management== Comparison to -sys Crate
[cols="1,2,2"] |=== |Aspect |ephapax-proven-sys |ephapax-proven (this crate)
|Safety |All functions unsafe |100% safe Rust API
|Memory |Manual free required |Automatic via Drop trait
|Errors |Null pointers, return codes |Result<T, Error>
|Types |Raw pointers |RAII wrappers
|Usage |Low-level FFI |High-level idiomatic Rust |===
== Performance
The safe wrappers add minimal overhead:
Benchmarks show <1% overhead compared to raw FFI.
== License
SPDX-License-Identifier: Palimpsest-1.0-or-later
Built on Mozilla Public License 2.0-or-later (MPL-2.0-or-later).
See https://github.com/hyperpolymath/palimpsest-license[Palimpsest License] for full text.
== Contributing
See link:CONTRIBUTING.adoc[] for guidelines.
This crate follows Hyperpolymath standards:
== Related Crates
== Acknowledgments
Built on the formally verified https://github.com/usernamehw/proven[Proven library] by Edwin Brady and contributors.