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

source

pub fn build(config: Config) -> Result<Self, BuildError>

Create a new instance of a Client based on the provided Config parameter.

source

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.

source

pub fn start_with_default_executor(&self)

Starts a client in the current thread, which must have a default tokio runtime.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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

source

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.

source

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.

source

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.

source

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.

source

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.

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more