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
impl FlagBuilder
Sourcepub fn new(key: impl Into<String>) -> Self
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)
Sourcepub fn boolean_flag(self) -> Self
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)
Sourcepub fn variations<I>(self, variations: I) -> Selfwhere
I: IntoIterator<Item = FlagValue>,
pub fn variations<I>(self, variations: I) -> Selfwhere
I: IntoIterator<Item = FlagValue>,
Sets the variations for this flag.
Sourcepub fn on(self, on: bool) -> Self
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.
Sourcepub fn fallthrough_variation(self, value: bool) -> Self
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.
Sourcepub fn fallthrough_variation_index(self, index: usize) -> Self
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.
Sourcepub fn off_variation(self, value: bool) -> Self
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.
Sourcepub fn off_variation_index(self, index: usize) -> Self
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).
Sourcepub fn variation_for_all(self, value: bool) -> Self
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
Sourcepub fn variation_for_all_index(self, index: usize) -> Self
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
Sourcepub fn value_for_all(self, value: FlagValue) -> Self
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
Sourcepub fn variation_for_user(
self,
user_key: impl Into<String>,
variation: bool,
) -> Self
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”.
Sourcepub fn variation_for_key(
self,
context_kind: Kind,
key: impl Into<String>,
variation: bool,
) -> Self
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.
Sourcepub fn variation_index_for_user(
self,
user_key: impl Into<String>,
variation: usize,
) -> Self
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”.
Sourcepub fn variation_index_for_key(
self,
context_kind: Kind,
key: impl Into<String>,
variation: usize,
) -> Self
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).
Sourcepub fn clear_targets(self) -> Self
pub fn clear_targets(self) -> Self
Removes all individual context targets from the flag.
Sourcepub fn if_match<I>(self, attribute: impl Into<String>, values: I) -> RuleBuilderwhere
I: IntoIterator<Item = AttributeValue>,
pub fn if_match<I>(self, attribute: impl Into<String>, values: I) -> RuleBuilderwhere
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.
Sourcepub fn if_match_context<I>(
self,
context_kind: Kind,
attribute: impl Into<String>,
values: I,
) -> RuleBuilderwhere
I: IntoIterator<Item = AttributeValue>,
pub fn if_match_context<I>(
self,
context_kind: Kind,
attribute: impl Into<String>,
values: I,
) -> RuleBuilderwhere
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.
Sourcepub fn if_not_match<I>(
self,
attribute: impl Into<String>,
values: I,
) -> RuleBuilderwhere
I: IntoIterator<Item = AttributeValue>,
pub fn if_not_match<I>(
self,
attribute: impl Into<String>,
values: I,
) -> RuleBuilderwhere
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.
Sourcepub fn if_not_match_context<I>(
self,
context_kind: Kind,
attribute: impl Into<String>,
values: I,
) -> RuleBuilderwhere
I: IntoIterator<Item = AttributeValue>,
pub fn if_not_match_context<I>(
self,
context_kind: Kind,
attribute: impl Into<String>,
values: I,
) -> RuleBuilderwhere
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.
Sourcepub fn clear_rules(self) -> Self
pub fn clear_rules(self) -> Self
Removes all rules from the flag.
Sourcepub fn sampling_ratio(self, ratio: u32) -> Self
pub fn sampling_ratio(self, ratio: u32) -> Self
Sets the event sampling ratio for the flag.
Sourcepub fn exclude_from_summaries(self, exclude: bool) -> Self
pub fn exclude_from_summaries(self, exclude: bool) -> Self
Sets whether the flag should be excluded from summary event counts.
Trait Implementations§
Source§impl Clone for FlagBuilder
impl Clone for FlagBuilder
Source§fn clone(&self) -> FlagBuilder
fn clone(&self) -> FlagBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FlagBuilder
impl RefUnwindSafe for FlagBuilder
impl Send for FlagBuilder
impl Sync for FlagBuilder
impl Unpin for FlagBuilder
impl UnsafeUnpin for FlagBuilder
impl UnwindSafe for FlagBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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