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, first create a config using crate::ConfigBuilder.
§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§
source§impl 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_and_callback(
&self,
event_received: Arc<dyn Fn(&SSE) + Send + Sync>,
)
pub fn start_with_default_executor_and_callback( &self, event_received: Arc<dyn Fn(&SSE) + Send + Sync>, )
Starts a client in the current thread, which must have a default tokio runtime. This variant accepts a callback for tracking the time of the last processed server event.
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, context: Context)
pub fn identify(&self, context: Context)
Identify reports details about a context.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/identify#rust
sourcepub fn bool_variation(
&self,
context: &Context,
flag_key: &str,
default: bool,
) -> bool
pub fn bool_variation( &self, context: &Context, flag_key: &str, default: bool, ) -> bool
Returns the value of a boolean feature flag for a given context.
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,
context: &Context,
flag_key: &str,
default: String,
) -> String
pub fn str_variation( &self, context: &Context, flag_key: &str, default: String, ) -> String
Returns the value of a string feature flag for a given context.
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,
context: &Context,
flag_key: &str,
default: f64,
) -> f64
pub fn float_variation( &self, context: &Context, flag_key: &str, default: f64, ) -> f64
Returns the value of a float feature flag for a given context.
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,
context: &Context,
flag_key: &str,
default: i64,
) -> i64
pub fn int_variation( &self, context: &Context, flag_key: &str, default: i64, ) -> i64
Returns the value of a integer feature flag for a given context.
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,
context: &Context,
flag_key: &str,
default: Value,
) -> Value
pub fn json_variation( &self, context: &Context, flag_key: &str, default: Value, ) -> Value
Returns the value of a feature flag for the given context, 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,
context: &Context,
flag_key: &str,
default: bool,
) -> Detail<bool>
pub fn bool_variation_detail( &self, context: &Context, 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,
context: &Context,
flag_key: &str,
default: String,
) -> Detail<String>
pub fn str_variation_detail( &self, context: &Context, 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,
context: &Context,
flag_key: &str,
default: f64,
) -> Detail<f64>
pub fn float_variation_detail( &self, context: &Context, 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,
context: &Context,
flag_key: &str,
default: i64,
) -> Detail<i64>
pub fn int_variation_detail( &self, context: &Context, 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,
context: &Context,
flag_key: &str,
default: Value,
) -> Detail<Value>
pub fn json_variation_detail( &self, context: &Context, 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, context: &Context) -> String
pub fn secure_mode_hash(&self, context: &Context) -> String
Generates the secure mode hash value for a context.
For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/secure-mode#rust.
sourcepub fn all_flags_detail(
&self,
context: &Context,
flag_state_config: FlagDetailConfig,
) -> FlagDetail
pub fn all_flags_detail( &self, context: &Context, flag_state_config: FlagDetailConfig, ) -> FlagDetail
Returns an object that encapsulates the state of all feature flags for a given context. 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,
context: &Context,
flag_key: &str,
default: T,
) -> Detail<FlagValue>
pub fn variation_detail<T: Into<FlagValue> + Clone>( &self, context: &Context, 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,
context: &Context,
flag_key: &str,
default: T,
) -> FlagValue
pub fn variation<T: Into<FlagValue> + Clone>( &self, context: &Context, flag_key: &str, default: T, ) -> FlagValue
This is a generic function which returns the value of a feature flag for a given context.
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, context: Context, key: impl Into<String>)
pub fn track_event(&self, context: Context, key: impl Into<String>)
Reports that a context 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,
context: Context,
key: impl Into<String>,
data: impl Serialize,
) -> Result<()>
pub fn track_data( &self, context: Context, key: impl Into<String>, data: impl Serialize, ) -> Result<()>
Reports that a context 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,
context: Context,
key: impl Into<String>,
value: f64,
data: impl Serialize,
)
pub fn track_metric( &self, context: Context, key: impl Into<String>, value: f64, data: impl Serialize, )
Reports that a context 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.