Skip to content

Commit

Permalink
feat: adjust pub fields
Browse files Browse the repository at this point in the history
Signed-off-by: YUE Daian <[email protected]>
  • Loading branch information
sheepduke committed Sep 15, 2023
1 parent 7302394 commit 17317bb
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
lazy_static! {
/// The singleton instance of [`OpenFeature`] struct.
/// The client should always use this instance to access OpenFeature APIs.
pub static ref SINGLETON: RwLock<OpenFeature> = RwLock::new(OpenFeature::default());
static ref SINGLETON: RwLock<OpenFeature> = RwLock::new(OpenFeature::default());
}

/// THE struct of the OpenFeature API.
Expand Down Expand Up @@ -48,13 +48,18 @@ impl OpenFeature {

/// Return the metadata of default (unnamed) provider.
pub async fn provider_metadata(&self) -> ProviderMetadata {
self.provider_registry.get_default().await.get().metadata()
self.provider_registry
.get_default()
.await
.get()
.metadata()
.clone()
}

/// Return the metadata of named provider (a provider bound to clients with this name).
pub async fn named_provider_metadata(&self, name: &str) -> Option<ProviderMetadata> {
match self.provider_registry.get_named(name).await {
Some(provider) => Some(provider.get().metadata()),
Some(provider) => Some(provider.get().metadata().clone()),
None => None,
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ use super::{

/// The metadata of OpenFeature client.
pub struct ClientMetadata {
name: String,
}

impl ClientMetadata {
pub fn name(&self) -> &str {
&self.name.as_ref()
}
pub name: String,
}

/// The OpenFeature client.
Expand Down
2 changes: 1 addition & 1 deletion src/api/global_evaluation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use crate::EvaluationContext;

#[derive(Clone, Default)]
pub struct GlobalEvaluationContext(pub Arc<RwLock<EvaluationContext>>);
pub struct GlobalEvaluationContext(Arc<RwLock<EvaluationContext>>);

impl GlobalEvaluationContext {
pub async fn get(&self) -> RwLockReadGuard<EvaluationContext> {
Expand Down
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod api;
pub use api::*;
pub use api::OpenFeature;

mod client;
pub use client::Client;
Expand Down
4 changes: 2 additions & 2 deletions src/evaluation/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl ToString for EvaluationReason {
/// Struct representing error
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct EvaluationError {
code: EvaluationErrorCode,
message: Option<String>,
pub code: EvaluationErrorCode,
pub message: Option<String>,
}

/// An enumerated error code represented idiomatically in the implementation language.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod api;
pub use api::*;
pub use api::{Client, OpenFeature};

mod evaluation;
pub use evaluation::*;
Expand Down
2 changes: 1 addition & 1 deletion src/provider/feature_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait FeatureProvider: Send + Sync + 'static {

/// The provider interface MUST define a metadata member or accessor, containing a name field
/// or accessor of type string, which identifies the provider implementation.
fn metadata(&self) -> ProviderMetadata;
fn metadata(&self) -> &ProviderMetadata;

/// Resolve given `flag_key` as a bool value.
async fn resolve_bool_value(
Expand Down
4 changes: 2 additions & 2 deletions src/provider/fixed_value_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl Default for FixedValueProvider {

#[async_trait]
impl FeatureProvider for FixedValueProvider {
fn metadata(&self) -> ProviderMetadata {
self.metadata.clone()
fn metadata(&self) -> &ProviderMetadata {
&self.metadata
}

async fn resolve_bool_value(
Expand Down
4 changes: 2 additions & 2 deletions src/provider/no_op_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl Default for NoOpProvider {

#[async_trait]
impl FeatureProvider for NoOpProvider {
fn metadata(&self) -> ProviderMetadata {
self.metadata.clone()
fn metadata(&self) -> &ProviderMetadata {
&self.metadata
}

async fn resolve_bool_value(
Expand Down

0 comments on commit 17317bb

Please sign in to comment.