Expand description
Scoped lending of borrowed references as Send-able smart pointers.
let mut greeting = String::from("hello ");
{
let scope = lien::scope!();
let mut g = scope.lend_mut(&mut greeting);
thread::spawn(move || {
g.push_str("beautiful ");
});
}
greeting.push_str("world");
assert_eq!(greeting, "hello beautiful world");A lien is “a right to take possession of a debtor’s property as security until a debt or duty is discharged.”
Similarly, a Lien represents a borrow of something from a Scope.
Like a static borrow with & or &mut, this forces the Scope to outlive
any Liens made from it, but like an Arc, Lien carries no lifetime
(it’s atomically reference-counted at runtime), is thread-safe, and can be
freely cloned.
§Smart pointers
Lien: a bare scope token.Ref: a sendable shared reference (like&T).RefMut: a sendable exclusive reference (like&mut T).
Both Ref and RefMut support sub-borrowing through Ref::map /
RefMut::map, which lets you re-lend fields against the original scope.
§#[no_std]
Disable the std feature:
[dependencies]
lien = { version = "0.1", default-features = false }Macros§
Structs§
- Lien
- A claim that holds a
Scopeopen. - Ref
- A sendable shared reference backed by a
Lien. - RefMut
- A sendable exclusive reference backed by a
Lien. - Rehypothecator
- A helper for
Ref::mapandRefMut::mapthat re-lends from existingRefs orRefMuts. - Scope
- A guard for the current scope to lend resources as long-lived borrows.