Struct launchdarkly_server_sdk::Context
source · 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<Context, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Context, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl Serialize for Context
impl Serialize for Context
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)