open_feature/provider/details.rs
1use typed_builder::TypedBuilder;
2
3use crate::{EvaluationReason, FlagMetadata};
4
5/// A structure which contains a subset of the fields defined in the evaluation details,
6/// representing the result of the provider's flag resolution process.
7#[derive(Clone, TypedBuilder, Debug)]
8pub struct ResolutionDetails<T> {
9 /// In cases of normal execution, the provider MUST populate the resolution details structure's
10 /// value field with the resolved flag value.
11 pub value: T,
12
13 /// In cases of normal execution, the provider SHOULD populate the resolution details
14 /// structure's variant field with a string identifier corresponding to the returned flag
15 /// value.
16 #[builder(default, setter(into, strip_option))]
17 pub variant: Option<String>,
18
19 /// The provider SHOULD populate the resolution details structure's reason field with "STATIC",
20 /// "DEFAULT", "TARGETING_MATCH", "SPLIT", "CACHED", "DISABLED", "UNKNOWN", "ERROR" or some
21 /// other string indicating the semantic reason for the returned flag value.
22 #[builder(default, setter(strip_option))]
23 pub reason: Option<EvaluationReason>,
24
25 /// The provider SHOULD populate the resolution details structure's flag metadata field.
26 #[builder(default, setter(strip_option))]
27 pub flag_metadata: Option<FlagMetadata>,
28}
29
30impl<T: Default> Default for ResolutionDetails<T> {
31 fn default() -> Self {
32 Self {
33 value: T::default(),
34 variant: None,
35 reason: None,
36 flag_metadata: None,
37 }
38 }
39}
40
41impl<T> ResolutionDetails<T> {
42 /// Create an instance given value.
43 pub fn new(value: impl Into<T>) -> Self {
44 Self {
45 value: value.into(),
46 variant: None,
47 reason: None,
48 flag_metadata: None,
49 }
50 }
51}