pub trait PotentialWell {
type Well<T>: KineticWell<Target = T>;
// Required method
fn new<T>(data: T) -> Self::Well<T>;
}Expand description
Potential well, representing a generic container.
Useful for recursive data structures, since it avoids recursive types.
§Examples
Atomic linked list via PotentialWell:
use potential_well::{PotentialWell, PotentialAtomicOption};
struct Link<T, W: PotentialWell = Box<()>> {
data: T,
next: PotentialAtomicOption<Link<T, W>, W>
}
struct List<T, W: PotentialWell = Box<()>> {
root: PotentialAtomicOption<Link<T, W>, W>,
}
let list: List<u32> = List {
root: PotentialAtomicOption::some(Box::new(Link {
data: 1,
next: PotentialAtomicOption::some(Box::new(Link {
data: 2,
next: PotentialAtomicOption::some(Box::new(Link {
data: 3,
next: PotentialAtomicOption::none(),
}))
})),
})),
};
// no Drop implementation needed!
drop(list);Without PotentialWell, you immediately run into trouble:
ⓘ
use potential_well::{Well, AtomicOption};
// recursive type: Link<T, Box<Link<T, Box<Link<T, ...>>>>>
struct Link<T, W: Well<Target = Link<T, Self>>> {
data: T,
next: AtomicOption<W>,
}
struct List<T, W: Well<Target = Link<T, Self>>> {
root: AtomicOption<W>,
}
let list: List<u32, Box<_>> = List {
root: AtomicOption::some(Box::new(Link {
data: 1,
next: AtomicOption::some(Box::new(Link {
data: 2,
next: AtomicOption::some(Box::new(Link {
data: 3,
next: AtomicOption::none(),
}))
})),
})),
};Required Associated Types§
Sourcetype Well<T>: KineticWell<Target = T>
type Well<T>: KineticWell<Target = T>
Makes a well of a particular type.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl PotentialWell for Box<()>
Available on crate features alloc only.
impl PotentialWell for Box<()>
Available on crate features
alloc only.Source§impl PotentialWell for Rc<()>
Available on crate feature alloc only.
impl PotentialWell for Rc<()>
Available on crate feature
alloc only.Source§impl PotentialWell for Weak<()>
Available on crate feature alloc only.
impl PotentialWell for Weak<()>
Available on crate feature
alloc only.Source§impl PotentialWell for Arc<()>
Available on crate features alloc only.
impl PotentialWell for Arc<()>
Available on crate features
alloc only.Source§impl PotentialWell for Weak<()>
Available on crate features alloc only.
impl PotentialWell for Weak<()>
Available on crate features
alloc only.