Struct wnf::StateCreation

source ·
pub struct StateCreation<L, S, SD> { /* private fields */ }
Expand description

A builder type for creating states

You can use this type to create a state by applying the following steps:

  1. Create a new builder using StateCreation::new
  2. Configure options using the appropriate methods on StateCreation
  3. Call StateCreation::create_owned or StateCreation::create_static to create the state

The following options can be configured:

Note that the StateCreation::create_owned and StateCreation::create_static methods are only available once the mandatory options have been configured.

§Example

use wnf::{CreatableStateLifetime, DataScope, OwnedState, StateCreation};

let state: OwnedState<u32> = StateCreation::new()
    .lifetime(CreatableStateLifetime::Temporary)
    .scope(DataScope::Machine)
    .create_owned()?;

If you want to create multiple states from a single builder, clone the builder first:

use wnf::{CreatableStateLifetime, DataScope, OwnedState, StateCreation};

let template = StateCreation::new()
    .lifetime(CreatableStateLifetime::Temporary)
    .scope(DataScope::Machine);

let large_state: OwnedState<u32> = template.clone().maximum_state_size(0x800).create_owned()?;

let small_state: OwnedState<u32> = template.maximum_state_size(0x400).create_owned()?;

In order to quickly create a temporary machine-scoped state (e.g. for testing purposes), consider using the OwnedState::create_temporary or BorrowedState::create_temporary methods.

Note that a newly created state is initialized with data of size zero. This means that unless the data type T is zero-sized or a slice type, you need to update the state data with a value of type T before querying it for the first time.

Implementations§

source§

impl StateCreation<UnspecifiedLifetime, UnspecifiedScope, UnspecifiedSecurityDescriptor>

source

pub const fn new() -> Self

Creates a new StateCreation builder with no configured options

source§

impl<L, S, SD> StateCreation<L, S, SD>

source

pub fn lifetime( self, lifetime: CreatableStateLifetime ) -> StateCreation<CreatableStateLifetime, S, SD>

Configures the lifetime of a StateCreation builder

This is a mandatory option and must be configured before a state can be created.

source

pub fn scope(self, scope: DataScope) -> StateCreation<L, DataScope, SD>

Configures the scope of a StateCreation builder

This is a mandatory option and must be configured before a state can be created.

source

pub fn maximum_state_size( self, maximum_state_size: usize ) -> StateCreation<L, S, SD>

Configures the maximum state size of a StateCreation builder

If this is not configured, it defaults to 0x1000 (4 KB), which is the absolute maximum size of a state.

source

pub fn security_descriptor<NewSD>( self, security_descriptor: NewSD ) -> StateCreation<L, S, NewSD>
where NewSD: Borrow<SecurityDescriptor>,

Configures the security descriptor of a StateCreation builder

If this is not configured, it defaults to BoxedSecurityDescriptor::create_everyone_generic_all.

source

pub fn type_id(self, type_id: impl Into<GUID>) -> StateCreation<L, S, SD>

Configures the type id of a StateCreation builder

If this is not configured, it defaults to no type id.

source§

impl<SD> StateCreation<CreatableStateLifetime, DataScope, SD>

source

pub fn create_owned<T>(self) -> Result<OwnedState<T>>
where T: ?Sized,

Creates an OwnedState<T> from this StateCreation

Note that the state will be deleted when the returned OwnedState<T> is dropped. You can avoid this by calling StateCreation::create_static instead, which returns a statically borrowed state.

This method is only available once StateCreation::lifetime and StateCreation::scope have been called.

§Errors

Returns an error if creating the state fails

source

pub fn create_static<T>(self) -> Result<BorrowedState<'static, T>>
where T: ?Sized,

Creates a state from this StateCreation, returning a BorrowedState<'static, T>

This is equivalent to creating an owned state and immediately leaking it:

let state: BorrowedState<'static, u32> = StateCreation::new()
    .lifetime(CreatableStateLifetime::Temporary)
    .scope(DataScope::Machine)
    .create_owned()?
    .leak();

Note that since you only obtain a statically borrowed state, it will not be deleted automatically. If that is not the desired behavior, call StateCreation::create_owned instead, which returns an owned state.

This method is only available once StateCreation::lifetime and StateCreation::scope have been called.

§Errors

Returns an error if creating the state fails

Trait Implementations§

source§

impl<L: Clone, S: Clone, SD: Clone> Clone for StateCreation<L, S, SD>

source§

fn clone(&self) -> StateCreation<L, S, SD>

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<L: Debug, S: Debug, SD: Debug> Debug for StateCreation<L, S, SD>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for StateCreation<UnspecifiedLifetime, UnspecifiedScope, UnspecifiedSecurityDescriptor>

source§

fn default() -> Self

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

impl<L: Hash, S: Hash, SD: Hash> Hash for StateCreation<L, S, SD>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<L: PartialEq, S: PartialEq, SD: PartialEq> PartialEq for StateCreation<L, S, SD>

source§

fn eq(&self, other: &StateCreation<L, S, SD>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<L: Copy, S: Copy, SD: Copy> Copy for StateCreation<L, S, SD>

source§

impl<L: Eq, S: Eq, SD: Eq> Eq for StateCreation<L, S, SD>

source§

impl<L, S, SD> StructuralPartialEq for StateCreation<L, S, SD>

Auto Trait Implementations§

§

impl<L, S, SD> Freeze for StateCreation<L, S, SD>
where L: Freeze, S: Freeze, SD: Freeze,

§

impl<L, S, SD> RefUnwindSafe for StateCreation<L, S, SD>

§

impl<L, S, SD> Send for StateCreation<L, S, SD>
where L: Send, S: Send, SD: Send,

§

impl<L, S, SD> Sync for StateCreation<L, S, SD>
where L: Sync, S: Sync, SD: Sync,

§

impl<L, S, SD> Unpin for StateCreation<L, S, SD>
where L: Unpin, S: Unpin, SD: Unpin,

§

impl<L, S, SD> UnwindSafe for StateCreation<L, S, SD>
where L: UnwindSafe, S: UnwindSafe, SD: 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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,

§

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>,

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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