Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Superposition Provider
Superposition provider is an openfeature provider that works with Superposition to manage configurations and experiments in your application. It allows you to fetch feature flags, configurations, and experiment variants from a Superposition server. Read the Superposition Provider Docs or docs.rs for more details.
Overview
The Superposition Provider integrates with OpenFeature to provide:
- Context Aware Configuration (CAC): Dynamic configuration management based on context
- Experimentation: A/B testing and feature experimentation capabilities
- Real-time Updates: Support for polling and on-demand refresh strategies
- Caching: Built-in caching for improved performance
Installation
Add this to your Cargo.toml:
[]
= "<version>"
= "0.2"
= { = "1.0", = ["full"] }
= "0.10"
OR
cargo add superposition_provider
Quick Start
Basic Usage
use ;
use OpenFeature;
use ;
async
Configuration Options
SuperpositionOptions
Core connection settings for the Superposition service:
let superposition_options = SuperpositionOptions ;
Refresh Strategies
Polling Strategy
Automatically fetches updates at regular intervals:
let polling_strategy = Polling;
On-Demand Strategy
Fetches updates only when requested, with TTL-based caching:
let on_demand_strategy = OnDemand;
Configuration Options
let cac_options = ConfigurationOptions ;
Advanced Usage
With Experimentation
Enable A/B testing and experimentation features:
use ExperimentationOptions;
let options = SuperpositionProviderOptions ;
Using Evaluation Context
Pass context for dynamic configuration evaluation:
use EvaluationContext;
use HashMap;
// Create evaluation context
let mut context = default;
context.targeting_key = Some;
// Add custom fields
let mut custom_fields = new;
custom_fields.insert;
custom_fields.insert;
context.custom_fields = custom_fields;
// Evaluate with context
let value = client.get_string_value.await?;
Fallback Configuration
Provide fallback values for when the service is unavailable:
use ;
let mut fallback_config = new;
fallback_config.insert;
fallback_config.insert;
fallback_config.insert;
let cac_options = ConfigurationOptions ;
Supported Value Types
The provider supports all OpenFeature value types:
// Boolean flags
let enabled: bool = client.get_bool_value.await?;
// String configuration
let api_url: String = client.get_string_value.await?;
// Integer values
let timeout: i64 = client.get_int_value.await?;
// Float values
let ratio: f64 = client.get_float_value.await?;
// Complex objects (StructValue)
let config: StructValue = client.get_struct_value.await?;
Error Handling
The provider handles various error scenarios gracefully:
match client.get_string_value.await
Performance Considerations
- Caching: Enable evaluation caching for frequently accessed flags
- Refresh Strategy: Choose polling for real-time updates or on-demand for better performance
- Fallback Config: Always provide fallback configuration for critical features
- Context Size: Keep evaluation context minimal for better performance
Logging
The provider uses the log crate for debugging. Enable logging to see detailed information:
init;
Set the log level with the RUST_LOG environment variable:
RUST_LOG=debug
Examples
See the example.rs file for a complete working example demonstrating basic usage with OpenFeature integration.