Lease Rs
A std-ish primitive for temporary ownership transfer in Rust.
This crate provides a comprehensive solution for the fundamental problem of temporarily transferring ownership of values across scopes, closures, and async boundaries. It solves the "cannot borrow across .await" problem and enables scoped mutation patterns that are otherwise impossible in safe Rust.
Installation
[]
= "0.1"
For no_std environments (embedded, WASM, etc.):
= { = "0.1", = false }
Quick Start
use lease_async_mut;
async
Key Features
- Zero-overhead by default - Operations that can be zero-cost are zero-cost
- Memory safety first - Never compromise Rust's safety guarantees
- Async cancellation safety - Automatic restoration on tokio::select! cancellation
- Explicit trade-offs - All performance and safety trade-offs are visible to users
- Complete API - 11 functions covering all common use cases
Quality Assurance
- 62 unit & doc tests - 100% coverage
- 25M+ fuzz executions - Zero crashes found
- Memory safety verified - Address sanitizer clean
- CI/CD pipeline - Automated testing on every PR
Performance
Most functions are zero-cost. Only async mutable operations with cancellation safety have runtime cost:
- Zero-cost (9/11 functions): All owned variants and sync mutable variants
- Non-zero-cost (2/11 functions):
lease_async_mut,try_lease_async_mut(requireT: Clone)
License
This project is 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.