Skip to main content

FlagBuilder

Struct FlagBuilder 

Source
pub struct FlagBuilder { /* private fields */ }
Expand description

Builder for constructing test flags with various configurations.

The flag builder provides a fluent API for creating flags with targeting rules, variations, and other configuration options. This is the primary way to create test flags for use in testing and development scenarios.

Implementations§

Source§

impl FlagBuilder

Source

pub fn key(&self) -> &str

Returns the flag key for this builder.

Source

pub fn new(key: impl Into<String>) -> Self

Creates a new flag builder for the given flag key.

If creating a new flag, it will be initialized as a boolean flag with:

  • Variations: [true, false]
  • Targeting enabled (on: true)
  • Fallthrough variation: 0 (true)
  • Off variation: 1 (false)
Source

pub fn boolean_flag(self) -> Self

Configures the flag as a boolean type with variations [true, false].

Sets:

  • Variations: [true, false]
  • Fallthrough variation: 0 (true)
  • Off variation: 1 (false)
Source

pub fn variations<I>(self, variations: I) -> Self
where I: IntoIterator<Item = FlagValue>,

Sets the variations for this flag.

Source

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

Sets whether targeting is enabled for the flag.

When targeting is off (false), the flag returns the off variation regardless of other configuration.

Source

pub fn fallthrough_variation(self, value: bool) -> Self

Sets the fallthrough variation for boolean flags.

This is a convenience method equivalent to calling fallthrough_variation_index with 0 for true or 1 for false.

Source

pub fn fallthrough_variation_index(self, index: usize) -> Self

Sets the fallthrough variation by index.

The fallthrough variation is returned when targeting is on but no targets or rules match.

Source

pub fn off_variation(self, value: bool) -> Self

Sets the off variation for boolean flags.

This is a convenience method equivalent to calling off_variation_index with 0 for true or 1 for false.

Source

pub fn off_variation_index(self, index: usize) -> Self

Sets the off variation by index.

The off variation is returned when targeting is disabled (on: false).

Source

pub fn variation_for_all(self, value: bool) -> Self

Configures the flag to always return the specified boolean value for everyone.

This is a convenience method that:

  • Enables targeting (on: true)
  • Removes all targets and rules
  • Sets the fallthrough variation to the specified value
Source

pub fn variation_for_all_index(self, index: usize) -> Self

Configures the flag to always return the specified variation index for everyone.

This is a convenience method that:

  • Enables targeting (on: true)
  • Removes all targets and rules
  • Sets the fallthrough variation to the specified index
Source

pub fn value_for_all(self, value: FlagValue) -> Self

Configures the flag to always return the specified value.

This is a convenience method that:

  • Sets a single variation equal to the specified value
  • Enables targeting (on: true)
  • Removes all targets and rules
  • Sets both fallthrough and off variation to index 0
Source

pub fn variation_for_user( self, user_key: impl Into<String>, variation: bool, ) -> Self

Configures the flag to return a specific boolean value for a user context.

This is a convenience method for targeting contexts with kind: “user”.

Source

pub fn variation_for_key( self, context_kind: Kind, key: impl Into<String>, variation: bool, ) -> Self

Configures the flag to return a specific boolean value for a context of any kind.

Source

pub fn variation_index_for_user( self, user_key: impl Into<String>, variation: usize, ) -> Self

Configures the flag to return a specific variation index for a user context.

This is a convenience method for targeting contexts with kind: “user”.

Source

pub fn variation_index_for_key( self, context_kind: Kind, key: impl Into<String>, variation: usize, ) -> Self

Configures the flag to return a specific variation index for a context of any kind.

When a context key is targeted, that key is automatically removed from targeting for any other variation of the same flag (a key can only be targeted for one variation at a time).

Source

pub fn clear_targets(self) -> Self

Removes all individual context targets from the flag.

Source

pub fn if_match<I>(self, attribute: impl Into<String>, values: I) -> RuleBuilder
where I: IntoIterator<Item = AttributeValue>,

Creates a rule that matches when the specified user attribute equals any of the provided values.

This is a convenience method for creating rules that target contexts with kind: “user”. Returns a RuleBuilder that can be used to add more conditions or complete the rule.

Source

pub fn if_match_context<I>( self, context_kind: Kind, attribute: impl Into<String>, values: I, ) -> RuleBuilder
where I: IntoIterator<Item = AttributeValue>,

Creates a rule that matches when the specified attribute equals any of the provided values for a context of the specified kind.

Returns a RuleBuilder that can be used to add more conditions or complete the rule.

Source

pub fn if_not_match<I>( self, attribute: impl Into<String>, values: I, ) -> RuleBuilder
where I: IntoIterator<Item = AttributeValue>,

Creates a rule that matches when the specified user attribute does NOT equal any of the provided values.

This is identical to if_match except it uses negated logic.

Source

pub fn if_not_match_context<I>( self, context_kind: Kind, attribute: impl Into<String>, values: I, ) -> RuleBuilder
where I: IntoIterator<Item = AttributeValue>,

Creates a rule that matches when the specified attribute does NOT equal any of the provided values for a context of the specified kind.

Source

pub fn clear_rules(self) -> Self

Removes all rules from the flag.

Source

pub fn sampling_ratio(self, ratio: u32) -> Self

Sets the event sampling ratio for the flag.

Source

pub fn exclude_from_summaries(self, exclude: bool) -> Self

Sets whether the flag should be excluded from summary event counts.

Source

pub fn build(self) -> Flag

Builds the final Flag instance.

This method creates a complete Flag with all configured settings.

Trait Implementations§

Source§

impl Clone for FlagBuilder

Source§

fn clone(&self) -> FlagBuilder

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.