launchdarkly_server_sdk_evaluation

Struct Detail

Source
pub struct Detail<T> {
    pub value: Option<T>,
    pub variation_index: Option<VariationIndex>,
    pub reason: Reason,
}
Expand description

A Detail instance is returned from evaluate, combining the result of a flag evaluation with an explanation of how it was calculated.

Fields§

§value: Option<T>

The result of the flag evaluation. This will be either one of the flag’s variations or None if no appropriate fallback value was configured.

§variation_index: Option<VariationIndex>

The index of the returned value within the flag’s list of variations, e.g. 0 for the first variation. This is an Option because it is possible for the value to be undefined (there is no variation index if the application default value was returned due to an error in evaluation) which is different from a value of 0.

§reason: Reason

A reason struct describing the main factor that influenced the flag evaluation value.

Implementations§

Source§

impl<T> Detail<T>

Source

pub fn empty(reason: Reason) -> Detail<T>

Returns a detail with value and variation_index of None.

If a flag does not have an appropriate fallback value, the Detail::value and Detail::variation_index must be None. In each case, the Detail::reason will be set to the reason provided to this method.

Source

pub fn err_default(error: Error, default: T) -> Detail<T>

Returns a detail response using the provided default as the value and a variation_index of None.

If the SDK variation methods detect some error condition, it will fallback to the user-provided default value. The provided error will be included as part of the Detail::reason, and the Detail::variation_index will be set to None.

Source

pub fn err(error: Error) -> Detail<T>

Returns a detail response using the provided error as the Detail::reason.

Source

pub fn map<U, F>(self, f: F) -> Detail<U>
where F: FnOnce(T) -> U,

Returns a new instance of this detail with the provided function f applied to Detail::value.

Source

pub fn should_have_value(self, e: Error) -> Detail<T>

Sets the Detail::reason to the provided error if the current detail instance does not have a value set.

Source

pub fn try_map<U, F>(self, f: F, default: U, e: Error) -> Detail<U>
where F: FnOnce(T) -> Option<U>,

Returns a new instance of detail with the provided function f applied to Detail::value if it exists.

Detail::value may or may not be set. If it is not set, this method will return a new Detail instance with the Detail::reason set to the provided Error e.

If it is set, this method will apply the provided function f to the value. If the method f returns None, this method will return an error Detail. See Detail::err. Otherwise, a Detail instance will be returned with the result of the f application.

Source

pub fn or(self, default: T) -> Detail<T>

Set the Detail::value to default if it does not exist.

The SDK always wants to return an evaluation result. This method helps ensure that if a Detail::value is None, we can update it with the provided default.

Source

pub fn or_else<F>(self, default: F) -> Detail<T>
where F: Fn() -> T,

Set the Detail::value to default if it does not exist.

This method accomplishes the same thing as Detail::or but allows the default value to be provided through the result of a callback. This helps reduce computation where an evaluation default value might be costly to calculate and is likely infrequently used.

Trait Implementations§

Source§

impl<T: Clone> Clone for Detail<T>

Source§

fn clone(&self) -> Detail<T>

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<T: Debug> Debug for Detail<T>

Source§

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

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

impl<T: PartialEq> PartialEq for Detail<T>

Source§

fn eq(&self, other: &Detail<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for Detail<T>

Auto Trait Implementations§

§

impl<T> Freeze for Detail<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Detail<T>
where T: RefUnwindSafe,

§

impl<T> Send for Detail<T>
where T: Send,

§

impl<T> Sync for Detail<T>
where T: Sync,

§

impl<T> Unpin for Detail<T>
where T: Unpin,

§

impl<T> UnwindSafe for Detail<T>
where T: 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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.