Skip to content

Commit

Permalink
chore: update readme for automated inclusion (#39)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
  • Loading branch information
toddbaert authored Nov 13, 2023
1 parent 959d3ed commit 7b52561
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- x-hide-in-docs-end -->
<!-- The 'github-badges' class is used in the docs -->
<p align="center" class="github-badges">
<a href="https://github.com/open-feature/spec/tree/v0.7.0">
<a href="https://github.com/open-feature/spec/releases/tag/v0.5.2">
<img alt="Specification" src="https://img.shields.io/static/v1?label=specification&message=v0.7.0&color=yellow&style=for-the-badge" />
</a>
<!-- x-release-please-start-version -->
Expand Down Expand Up @@ -48,17 +48,37 @@ Add the following content to the `Cargo.toml` file:
open-feature = "0.1.2"
```
<!-- x-release-please-end -->

### Usage

#### Basic Usage
```rust
async fn example() -> Result<(), Error> {
// Acquire an OpenFeature API instance.
let mut api = OpenFeature::singleton_mut().await;

// configure a provider
api.set_provider(NoOpProvider::new())
.await;

// create a client
let client = api.get_client();

// get a bool flag value
let is_feature_enabled = client
.get_bool_value("v2_enabled", false, None)
.await;

Ok(())
}
```

#### Extended Example

```rust
#[derive(Clone, Default, Debug)]
struct MyStruct {}

#[tokio::test]
async fn example() {
async fn extended_example() {
// Acquire an OpenFeature API instance.
// Note the `await` call here because asynchronous lock is used to guarantee thread safety.
let mut api = OpenFeature::singleton_mut().await;
Expand Down Expand Up @@ -178,7 +198,7 @@ api.set_provider(NoOpProvider::default()).await;
```

In some situations, it may be beneficial to register multiple providers in the same application.
This is possible using [named clients](#named-clients), which is covered in more details below.
This is possible using [named clients](#named-clients), which is covered in more detail below.

### Targeting

Expand Down Expand Up @@ -215,12 +235,12 @@ Once you've added a hook as a dependency, it can be registered at the global, cl

### Logging

<!-- TODO: talk about logging config, and code example -->
Logging customization is not yet available in the Rust SDK.

### Named clients

Clients can be given a name.
A name is a logical identifier which can be used to associate clients with a particular provider.
A name is a logical identifier that can be used to associate clients with a particular provider.
If a name has no associated provider, the global provider is used.

```rust
Expand All @@ -235,9 +255,10 @@ let client = api.create_named_client("named");

assert_eq!(client.get_int_value("key", None, None).await.unwrap(), 42);
```

### Eventing

Events are not yet available in the Rust SDK.

<!-- TOOD: Uncomment it when we support events
Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.
Initialization events (`PROVIDER_READY` on success, `PROVIDER_ERROR` on failure) are dispatched for every provider.
Expand Down

0 comments on commit 7b52561

Please sign in to comment.