Struct launchdarkly_server_sdk::Client
source · [−]pub struct Client { /* private fields */ }
Expand description
A client for the LaunchDarkly API.
In order to create a client instance you must first create a crate::Config.
Examples
Creating a client, with default configuration.
let ld_client = Client::build(ConfigBuilder::new("sdk-key").build())?;
Creating an instance which connects to a relay proxy.
let ld_client = Client::build(ConfigBuilder::new("sdk-key")
.service_endpoints(ServiceEndpointsBuilder::new()
.relay_proxy("http://my-relay-hostname:8080")
).build()
)?;
Each builder type includes usage examples for the builder.
Implementations
sourceimpl Client
impl Client
sourcepub fn build(config: Config) -> Result<Self, BuildError>
pub fn build(config: Config) -> Result<Self, BuildError>
sourcepub fn start_with_default_executor(&self)
pub fn start_with_default_executor(&self)
Starts a client in the current thread, which must have a default tokio runtime.
sourcepub fn start_with_runtime(&self) -> Result<bool, StartError>
pub fn start_with_runtime(&self) -> Result<bool, StartError>
Creates a new tokio runtime and then starts the client. Tasks from the client will be executed on created runtime. If your application already has a tokio runtime, then you can use crate::Client::start_with_default_executor and the client will dispatch tasks to your existing runtime.
sourcepub async fn initialized_async(&self) -> bool
pub async fn initialized_async(&self) -> bool
This is an async method that will resolve once initialization is complete. Initialization being complete does not mean that initialization was a success. The return value from the method indicates if the client successfully initialized.
sourcepub fn initialized(&self) -> bool
pub fn initialized(&self) -> bool
This function synchronously returns if the SDK is initialized. In the case of unrecoverable errors in establishing a connection it is possible for the SDK to never become initialized.
sourcepub fn close(&self)
pub fn close(&self)
Close shuts down the LaunchDarkly client. After calling this, the LaunchDarkly client should no longer be used. The method will block until all pending analytics events (if any) been sent.
sourcepub fn flush(&self)
pub fn flush(&self)
Flush tells the client that all pending analytics events (if any) should be delivered as soon as possible. Flushing is asynchronous, so this method will return before it is complete. However, if you call Client::close, events are guaranteed to be sent before that method returns.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/flush#rust.
sourcepub fn identify(&self, user: User)
pub fn identify(&self, user: User)
Identify reports details about a user.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/identify#rust
sourcepub fn alias(&self, user: User, previous_user: User)
pub fn alias(&self, user: User, previous_user: User)
Alias associates two users for analytics purposes.
This can be helpful in the situation where a person is represented by multiple LaunchDarkly users. This may happen, for example, when a person initially logs into an application– the person might be represented by an anonymous user prior to logging in and a different user after logging in, as denoted by a different user key.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/aliasing-users#rust.
sourcepub fn bool_variation(&self, user: &User, flag_key: &str, default: bool) -> bool
pub fn bool_variation(&self, user: &User, flag_key: &str, default: bool) -> bool
Returns the value of a boolean feature flag for a given user.
Returns default
if there is an error, if the flag doesn’t exist, or the feature is turned
off and has no off variation.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#rust.
sourcepub fn str_variation(
&self,
user: &User,
flag_key: &str,
default: String
) -> String
pub fn str_variation(
&self,
user: &User,
flag_key: &str,
default: String
) -> String
Returns the value of a string feature flag for a given user.
Returns default
if there is an error, if the flag doesn’t exist, or the feature is turned
off and has no off variation.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#rust.
sourcepub fn float_variation(&self, user: &User, flag_key: &str, default: f64) -> f64
pub fn float_variation(&self, user: &User, flag_key: &str, default: f64) -> f64
Returns the value of a float feature flag for a given user.
Returns default
if there is an error, if the flag doesn’t exist, or the feature is turned
off and has no off variation.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#rust.
sourcepub fn int_variation(&self, user: &User, flag_key: &str, default: i64) -> i64
pub fn int_variation(&self, user: &User, flag_key: &str, default: i64) -> i64
Returns the value of a integer feature flag for a given user.
Returns default
if there is an error, if the flag doesn’t exist, or the feature is turned
off and has no off variation.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#rust.
sourcepub fn json_variation(
&self,
user: &User,
flag_key: &str,
default: Value
) -> Value
pub fn json_variation(
&self,
user: &User,
flag_key: &str,
default: Value
) -> Value
Returns the value of a feature flag for the given user, allowing the value to be of any JSON type.
The value is returned as an serde_json::Value.
Returns default
if there is an error, if the flag doesn’t exist, or the feature is turned off.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#rust.
sourcepub fn bool_variation_detail(
&self,
user: &User,
flag_key: &str,
default: bool
) -> Detail<bool>
pub fn bool_variation_detail(
&self,
user: &User,
flag_key: &str,
default: bool
) -> Detail<bool>
This method is the same as Client::bool_variation, but also returns further information about how the value was calculated. The “reason” data will also be included in analytics events.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#rust.
sourcepub fn str_variation_detail(
&self,
user: &User,
flag_key: &str,
default: String
) -> Detail<String>
pub fn str_variation_detail(
&self,
user: &User,
flag_key: &str,
default: String
) -> Detail<String>
This method is the same as Client::str_variation, but also returns further information about how the value was calculated. The “reason” data will also be included in analytics events.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#rust.
sourcepub fn float_variation_detail(
&self,
user: &User,
flag_key: &str,
default: f64
) -> Detail<f64>
pub fn float_variation_detail(
&self,
user: &User,
flag_key: &str,
default: f64
) -> Detail<f64>
This method is the same as Client::float_variation, but also returns further information about how the value was calculated. The “reason” data will also be included in analytics events.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#rust.
sourcepub fn int_variation_detail(
&self,
user: &User,
flag_key: &str,
default: i64
) -> Detail<i64>
pub fn int_variation_detail(
&self,
user: &User,
flag_key: &str,
default: i64
) -> Detail<i64>
This method is the same as Client::int_variation, but also returns further information about how the value was calculated. The “reason” data will also be included in analytics events.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#rust.
sourcepub fn json_variation_detail(
&self,
user: &User,
flag_key: &str,
default: Value
) -> Detail<Value>
pub fn json_variation_detail(
&self,
user: &User,
flag_key: &str,
default: Value
) -> Detail<Value>
This method is the same as Client::json_variation, but also returns further information about how the value was calculated. The “reason” data will also be included in analytics events.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#rust.
sourcepub fn secure_mode_hash(&self, user: &User) -> String
pub fn secure_mode_hash(&self, user: &User) -> String
Generates the secure mode hash value for a user.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/secure-mode#rust.
sourcepub fn all_flags_detail(
&self,
user: &User,
flag_state_config: FlagDetailConfig
) -> FlagDetail
pub fn all_flags_detail(
&self,
user: &User,
flag_state_config: FlagDetailConfig
) -> FlagDetail
Returns an object that encapsulates the state of all feature flags for a given user. This includes the flag values, and also metadata that can be used on the front end.
The most common use case for this method is to bootstrap a set of client-side feature flags from a back-end service.
You may pass any configuration of FlagDetailConfig to control what data is included.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/all-flags#rust
sourcepub fn variation_detail<T: Into<FlagValue> + Clone>(
&self,
user: &User,
flag_key: &str,
default: T
) -> Detail<FlagValue>
pub fn variation_detail<T: Into<FlagValue> + Clone>(
&self,
user: &User,
flag_key: &str,
default: T
) -> Detail<FlagValue>
This method is the same as Client::variation, but also returns further information about how the value was calculated. The “reason” data will also be included in analytics events.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluation-reasons#rust.
sourcepub fn variation<T: Into<FlagValue> + Clone>(
&self,
user: &User,
flag_key: &str,
default: T
) -> FlagValue
pub fn variation<T: Into<FlagValue> + Clone>(
&self,
user: &User,
flag_key: &str,
default: T
) -> FlagValue
This is a generic function which returns the value of a feature flag for a given user.
This method is an alternatively to the type specified methods (e.g. Client::bool_variation, Client::int_variation, etc.).
Returns default
if there is an error, if the flag doesn’t exist, or the feature is turned
off and has no off variation.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/evaluating#rust.
sourcepub fn track_event(&self, user: User, key: impl Into<String>)
pub fn track_event(&self, user: User, key: impl Into<String>)
Reports that a user has performed an event.
The key
parameter is defined by the application and will be shown in analytics reports;
it normally corresponds to the event name of a metric that you have created through the
LaunchDarkly dashboard. If you want to associate additional data with this event, use
Client::track_data or Client::track_metric.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/events#rust.
sourcepub fn track_data(
&self,
user: User,
key: impl Into<String>,
data: impl Serialize
) -> Result<()>
pub fn track_data(
&self,
user: User,
key: impl Into<String>,
data: impl Serialize
) -> Result<()>
Reports that a user has performed an event, and associates it with custom data.
The key
parameter is defined by the application and will be shown in analytics reports;
it normally corresponds to the event name of a metric that you have created through the
LaunchDarkly dashboard.
data
parameter is any type that implements Serialize. If no such value is needed, use
serde_json::Value::Null (or call Client::track_event instead). To send a numeric value
for experimentation, use Client::track_metric.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/events#rust.
sourcepub fn track_metric(
&self,
user: User,
key: impl Into<String>,
value: f64,
data: impl Serialize
)
pub fn track_metric(
&self,
user: User,
key: impl Into<String>,
value: f64,
data: impl Serialize
)
Reports that a user has performed an event, and associates it with a numeric value. This value is used by the LaunchDarkly experimentation feature in numeric custom metrics, and will also be returned as part of the custom event for Data Export.
The key
parameter is defined by the application and will be shown in analytics reports;
it normally corresponds to the event name of a metric that you have created through the
LaunchDarkly dashboard.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/events#rust.
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more