Runtime Ownership for Rust
This library provides dynamic ownership management with runtime enforcement of ownership rules. The type system ensures safe data access patterns while maintaining flexibility.
Core Types
Primary Ownership
Owner<T>- Exclusive ownership with modify and view rightsViewer<T>- Shared read-only view accessHolder<T>- Opaque reference that can be upgraded toOwner<T>orViewer<T>
Projection Types
OwnerRef<S, T>- Exclusive ownership with field projectionViewerRef<S, T>- Read-only view with field projection
Ownership Rules
- Exclusive Access:
Owner/OwnerRefcannot coexist with otherOwner,OwnerRef, orViewer/ViewerRef - Shared View: Multiple
Viewer/ViewerRefinstances can coexist - Reference Holding: All types may coexist with
Holderinstances
Type Conversions
Creation
Owner<T>→OwnerRef<T, T>Viewer<T>→ViewerRef<T, T>- Any type can be downgraded to
Holder<T>
Recovery
OwnerRef<S, T>→Owner<S>ViewerRef<S, T>→Viewer<S>Holder<T>can upgrade toOwner<T>orViewer<T>
Projection & Mapping
The *Ref types enable flexible field access:
- Projection: View nested fields of the root object to arbitrary depth
- Mapping:
*Ref<A, B>→*Ref<A, C>whereBis a direct or indirect field ofAandCis a direct or indirect field ofB - Preservation: All operations maintain the original ownership semantics
Example
Example for Owner, Viewer and Holder:
use Holder;
use Owner;
use Viewer;
Example for OwnerRef and ViewerRef:
use Owner;
use OwnerRef;
use Viewer;
use ViewerRef;
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.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.