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§

Returns true if the context is a multi-context.

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.

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.

Returns the canonical key.

  1. For a single context of kind “user”, the canonical key is equivalent to the key.
  2. For other kinds of single contexts, the canonical key is “kind:key”.
  3. For a multi-context, the canonical key is the concatenation of its constituent contexts’ canonical keys with : according to (2) (including kind “user”).

Returns the “kind” attribute.

If the specified kind exists within the context, returns a reference to it. Otherwise, returns None.

Returns a map of all (kind, key) pairs contained in this context.

Returns a list of all kinds represented by this context.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more