Struct launchdarkly_server_sdk::Detail
source · pub struct Detail<T> {
pub value: Option<T>,
pub variation_index: Option<isize>,
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<isize>
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>
impl<T> Detail<T>
sourcepub fn empty(reason: Reason) -> Detail<T>
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.
sourcepub fn err_default(error: Error, default: T) -> Detail<T>
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.
sourcepub fn err(error: Error) -> Detail<T>
pub fn err(error: Error) -> Detail<T>
Returns a detail response using the provided error as the Detail::reason.
sourcepub fn map<U, F>(self, f: F) -> Detail<U>where
F: FnOnce(T) -> U,
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.
sourcepub fn should_have_value(self, e: Error) -> Detail<T>
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.
sourcepub fn try_map<U, F>(self, f: F, default: U, e: Error) -> Detail<U>
pub fn try_map<U, F>(self, f: F, default: U, e: Error) -> Detail<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.
sourcepub fn or(self, default: T) -> Detail<T>
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.
sourcepub fn or_else<F>(self, default: F) -> Detail<T>where
F: Fn() -> T,
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§
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> 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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)