Struct glock::GLockBuilder
source · pub struct GLockBuilder { /* private fields */ }
Expand description
A GLockBuilder
can be used to construct nested GLock
s. In Rust, inner struct
s are
initialized before their outer container struct
s. In glock
, parent lock kernels must be
initialized before child lock kernels. To resolve this, a GLockBuilder
can be used to
initialize the parent lock kernel first, then accept the containing struct
in build()
.
Example
use glock::{ GLock, GLockBuilder };
struct Parent {
child1: GLock<u32>,
child2: GLock<u32>,
}
let parent_lock = {
let parent_lock_builder = GLockBuilder::new_root_builder();
let parent = Parent {
child1: parent_lock_builder.new_child(0u32).unwrap(),
child2: parent_lock_builder.new_child(0u32).unwrap(),
};
parent_lock_builder.build(parent).unwrap()
};
Implementations§
source§impl GLockBuilder
impl GLockBuilder
sourcepub fn new_root_builder() -> GLockBuilder
pub fn new_root_builder() -> GLockBuilder
Creates a new root GLock
builder
sourcepub fn new_child_builder(&self) -> LockResult<GLockBuilder>
pub fn new_child_builder(&self) -> LockResult<GLockBuilder>
Creates a builder for a GLock
that is a child of the current GLock
.
sourcepub fn new_child<T>(&self, data: T) -> LockResult<GLock<T>>
pub fn new_child<T>(&self, data: T) -> LockResult<GLock<T>>
Creates a new Glock
that is a child of the current GLock
and protects the specified.
sourcepub fn build<T>(self, data: T) -> LockResult<GLock<T>>
pub fn build<T>(self, data: T) -> LockResult<GLock<T>>
Builds the GLock
object that protects the specified data
.