Struct ObjectBuilder

Source
pub struct ObjectBuilder<Base: BaseType> { /* private fields */ }
Expand description

An object builder, for constructing objects using a builder API.

Implementations§

Source§

impl<Base: BaseType> ObjectBuilder<Base>

Source

pub fn new(spec: ObjectCreate) -> Self

Make a new object builder.

Source

pub fn persist(self, persist: bool) -> Self

Make the object persistent.

Source

pub fn cast<U: BaseType>(self) -> ObjectBuilder<U>

Cast the base type.

Source

pub fn add_src(self, obj_src: ObjectSource) -> Self

Add a Source Object that this new object will copy from.

Source

pub fn add_tie(self, tie: CreateTieSpec) -> Self

Add a tie specification for this object creation.

Source

pub fn named(self, name: impl ToString) -> Self

Source§

impl<Base: BaseType + StoreCopy> ObjectBuilder<Base>

Source

pub fn build(&self, base: Base) -> Result<Object<Base>>

Build an object using the provided base value.

§Panics

This function may panic if the default permissions dont contain READ and WRITE. If your usecase requires that the default permissions for an object can’t contain those flags, please look at the twizzler_security::SecureBuilderExt trait.

§Example
let builder = ObjectBuilder::default();
let obj = builder.build(42u32).unwrap();
Source§

impl<Base: BaseType> ObjectBuilder<Base>

Source

pub fn build_inplace<F>(&self, ctor: F) -> Result<Object<Base>>
where F: FnOnce(TxObject<MaybeUninit<Base>>) -> Result<TxObject<Base>>,

Build an object using the provided constructor function.

The constructor should call the .write() method on the TxObject, and return the result.

§Example
let builder = ObjectBuilder::default();
let obj = builder.build_inplace(|tx| tx.write(42u32)).unwrap();
Source

pub unsafe fn build_ctor<F>(&self, ctor: F) -> Result<Object<Base>>
where F: FnOnce(&mut TxObject<MaybeUninit<Base>>),

Build an object using the provided constructor function.

The constructor should call the .write() method on the TxObject or otherwise ensure that it is safe to call .assume_init on the underlying MaybeUninit.

§Safety

The caller must ensure that the base is initialized, see MaybeUninit::assume_init.

§Example
let builder = ObjectBuilder::default();
let obj = unsafe {
    builder
        .build_ctor(|tx| {
            tx.write(42u32);
        })
        .unwrap()
};

Trait Implementations§

Source§

impl<Base: Clone + BaseType> Clone for ObjectBuilder<Base>

Source§

fn clone(&self) -> ObjectBuilder<Base>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Base: BaseType> Default for ObjectBuilder<Base>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Base> Freeze for ObjectBuilder<Base>

§

impl<Base> !ObjSafe for ObjectBuilder<Base>

§

impl<Base> RefUnwindSafe for ObjectBuilder<Base>
where Base: RefUnwindSafe,

§

impl<Base> Send for ObjectBuilder<Base>
where Base: Send,

§

impl<Base> StoreCopy for ObjectBuilder<Base>
where Base: StoreCopy,

§

impl<Base> Sync for ObjectBuilder<Base>
where Base: Sync,

§

impl<Base> Unpin for ObjectBuilder<Base>
where Base: Unpin,

§

impl<Base> UnwindSafe for ObjectBuilder<Base>
where Base: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more