pub struct Context { /* private fields */ }
Expand description
Context is a collection of attributes that can be referenced in flag evaluations and analytics events. These attributes are described by one or more Kinds.
For example, a context might represent the user of a service, the description of an organization, IoT device metadata, or any combination of those at once.
To create a context of a single kind, such as a user, you may use crate::ContextBuilder.
To create a context with multiple kinds, use crate::MultiContextBuilder.
Implementations§
Source§impl Context
impl Context
Sourcepub fn get_value(&self, reference: &Reference) -> Option<AttributeValue>
pub fn get_value(&self, reference: &Reference) -> Option<AttributeValue>
Looks up the value of any attribute of the context, or a value contained within an attribute, based on the given reference.
This lookup includes only attributes that are addressable in evaluations– not metadata such as private attributes.
This method implements the same behavior that the SDK uses to resolve attribute references during a flag evaluation. In a single context, the reference can represent a simple attribute name– either a built-in one like “name” or “key”, or a custom attribute that was set by methods like crate::ContextBuilder::set_string– or, it can be a slash-delimited path.
For a multi-context, the only supported attribute name is “kind”. Use Context::as_kind to inspect a context for a particular Kind and then get its attributes.
Sourcepub fn key(&self) -> &str
pub fn key(&self) -> &str
Returns the “key” attribute.
For a single context, this value is set by the crate::ContextBuilder::new or crate::ContextBuilder::key methods.
For a multi-context, there is no single key, so Context::key returns an empty string; use Context::as_kind to inspect a context for a particular kind and call Context::key on it.
Sourcepub fn canonical_key(&self) -> &str
pub fn canonical_key(&self) -> &str
Returns the canonical key.
- For a single context of kind “user”, the canonical key is equivalent to the key.
- For other kinds of single contexts, the canonical key is “kind:key”.
- For a multi-context, the canonical key is the concatenation of its constituent contexts’
canonical keys with
:
according to (2) (including kind “user”).
Sourcepub fn as_kind(&self, kind: &Kind) -> Option<&Context>
pub fn as_kind(&self, kind: &Kind) -> Option<&Context>
If the specified kind exists within the context, returns a reference to it. Otherwise, returns None.
Sourcepub fn context_keys(&self) -> HashMap<&Kind, &str>
pub fn context_keys(&self) -> HashMap<&Kind, &str>
Returns a map of all (kind, key) pairs contained in this context.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)