From a327229f6b774d297a0befe3909b25b3252e8be9 Mon Sep 17 00:00:00 2001 From: Oleksii Shmalko Date: Fri, 27 Sep 2024 21:48:18 +0300 Subject: [PATCH] refactor: rename ArcStr to Str --- eppo_core/Cargo.toml | 2 +- eppo_core/src/attributes.rs | 10 ++--- eppo_core/src/context_attributes.rs | 8 ++-- eppo_core/src/eval/eval_assignment.rs | 22 +++++----- eppo_core/src/eval/eval_bandits.rs | 28 ++++++------ eppo_core/src/eval/eval_details.rs | 12 +++--- eppo_core/src/eval/eval_details_builder.rs | 16 +++---- eppo_core/src/eval/evaluator.rs | 14 +++--- eppo_core/src/events.rs | 16 +++---- eppo_core/src/lib.rs | 2 +- eppo_core/src/str.rs | 50 +++++++++++----------- eppo_core/src/ufc/assignment.rs | 6 +-- eppo_core/src/ufc/compiled_flag_config.rs | 16 +++---- eppo_core/src/ufc/models.rs | 18 ++++---- python-sdk/src/client.rs | 34 +++++++-------- rust-sdk/src/client.rs | 34 +++++++-------- 16 files changed, 144 insertions(+), 144 deletions(-) diff --git a/eppo_core/Cargo.toml b/eppo_core/Cargo.toml index 3ca86417..e6b74a6e 100644 --- a/eppo_core/Cargo.toml +++ b/eppo_core/Cargo.toml @@ -16,6 +16,7 @@ pyo3 = ["dep:pyo3", "dep:serde-pyobject"] [dependencies] chrono = { version = "0.4.38", features = ["serde"] } derive_more = "0.99.17" +faststr = { version = "0.2.23", features = ["serde"] } log = { version = "0.4.21", features = ["kv", "kv_serde"] } md5 = "0.7.0" rand = "0.8.5" @@ -30,7 +31,6 @@ url = "2.5.0" # pyo3 dependencies pyo3 = { version = "0.22.0", optional = true, default-features = false } serde-pyobject = { version = "0.4.0", optional = true} -faststr = { version = "0.2.23", features = ["serde"] } [dev-dependencies] criterion = { version = "0.4", features = ["html_reports"] } diff --git a/eppo_core/src/attributes.rs b/eppo_core/src/attributes.rs index 72e62b71..1fac02fd 100644 --- a/eppo_core/src/attributes.rs +++ b/eppo_core/src/attributes.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, sync::Arc}; use derive_more::From; use serde::{Deserialize, Serialize}; -use crate::ArcStr; +use crate::Str; /// `Subject` is a bundle of subject attributes and a key. #[derive(Debug)] @@ -15,14 +15,14 @@ pub(crate) struct Subject { } impl Subject { - pub fn new(key: ArcStr, attributes: Arc) -> Subject { + pub fn new(key: Str, attributes: Arc) -> Subject { Subject { key: AttributeValue::String(key), attributes, } } - pub fn key(&self) -> &ArcStr { + pub fn key(&self) -> &Str { let AttributeValue::String(s) = &self.key else { unreachable!("Subject::key is always encoded as AttributeValue::ArcString()"); }; @@ -74,7 +74,7 @@ pub type Attributes = HashMap; pub enum AttributeValue { /// A string value. #[from(ignore)] - String(ArcStr), + String(Str), /// A numerical value. Number(f64), /// A boolean value. @@ -83,7 +83,7 @@ pub enum AttributeValue { Null, } -impl> From for AttributeValue { +impl> From for AttributeValue { fn from(value: T) -> AttributeValue { AttributeValue::String(value.into()) } diff --git a/eppo_core/src/context_attributes.rs b/eppo_core/src/context_attributes.rs index 16ffe72b..f7005675 100644 --- a/eppo_core/src/context_attributes.rs +++ b/eppo_core/src/context_attributes.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use crate::{ArcStr, AttributeValue, Attributes}; +use crate::{AttributeValue, Attributes, Str}; /// `ContextAttributes` are subject or action attributes split by their semantics. #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -18,7 +18,7 @@ pub struct ContextAttributes { /// Categorical attributes are attributes that have a finite set of values that are not directly /// comparable (i.e., enumeration). #[serde(alias = "categoricalAttributes")] - pub categorical: HashMap, + pub categorical: HashMap, } impl From for ContextAttributes { @@ -82,7 +82,7 @@ mod pyo3_impl { use pyo3::prelude::*; - use crate::{ArcStr, Attributes}; + use crate::{Attributes, Str}; use super::ContextAttributes; @@ -91,7 +91,7 @@ mod pyo3_impl { #[new] fn new( numeric_attributes: HashMap, - categorical_attributes: HashMap, + categorical_attributes: HashMap, ) -> ContextAttributes { ContextAttributes { numeric: numeric_attributes, diff --git a/eppo_core/src/eval/eval_assignment.rs b/eppo_core/src/eval/eval_assignment.rs index b3cb4d38..4096190e 100644 --- a/eppo_core/src/eval/eval_assignment.rs +++ b/eppo_core/src/eval/eval_assignment.rs @@ -10,7 +10,7 @@ use crate::{ Allocation, Assignment, AssignmentValue, CompiledFlagsConfig, Flag, Shard, Split, Timestamp, VariationType, }, - ArcStr, Attributes, Configuration, + Attributes, Configuration, Str, }; use super::{ @@ -27,7 +27,7 @@ use super::{ pub fn get_assignment( configuration: Option<&Configuration>, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, now: DateTime, @@ -47,7 +47,7 @@ pub fn get_assignment( pub fn get_assignment_details( configuration: Option<&Configuration>, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, now: DateTime, @@ -96,7 +96,7 @@ pub(super) fn get_assignment_with_visitor( configuration: Option<&Configuration>, visitor: &mut V, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, now: DateTime, @@ -163,7 +163,7 @@ impl CompiledFlagsConfig { &self, visitor: &mut V, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, now: DateTime, @@ -205,7 +205,7 @@ impl Flag { fn eval( &self, visitor: &mut V, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, now: DateTime, ) -> Result { @@ -320,7 +320,7 @@ mod tests { get_assignment, get_assignment_details, }, ufc::{RuleWire, UniversalFlagConfig, ValueWire, VariationType}, - ArcStr, Attributes, Configuration, SdkMetadata, + Attributes, Configuration, SdkMetadata, Str, }; #[derive(Debug, Serialize, Deserialize)] @@ -342,7 +342,7 @@ mod tests { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct TestSubject { - subject_key: ArcStr, + subject_key: Str, subject_attributes: Arc, assignment: DefaultValue, evaluation_details: TruncatedEvaluationDetails, @@ -352,13 +352,13 @@ mod tests { #[serde(rename_all = "camelCase")] struct TruncatedEvaluationDetails { /// Environment the configuration belongs to. None if configuration hasn't been fetched yet. - environment_name: Option, + environment_name: Option, flag_evaluation_code: TruncatedFlagEvaluationCode, flag_evaluation_description: String, /// Key of the selected variation. - variation_key: Option, + variation_key: Option, /// Value of the selected variation. Could be `None` if no variation is selected, or selected /// value is absent in configuration (configuration error). variation_value: serde_json::Value, @@ -394,7 +394,7 @@ mod tests { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct TruncatedAllocationEvaluationDetails { - pub key: ArcStr, + pub key: Str, /// Order position of the allocation as seen in the Web UI. pub order_position: usize, pub allocation_evaluation_code: AllocationEvaluationCode, diff --git a/eppo_core/src/eval/eval_bandits.rs b/eppo_core/src/eval/eval_bandits.rs index 861fcf4d..00e2cf34 100644 --- a/eppo_core/src/eval/eval_bandits.rs +++ b/eppo_core/src/eval/eval_bandits.rs @@ -11,7 +11,7 @@ use crate::error::EvaluationFailure; use crate::events::{AssignmentEvent, BanditEvent}; use crate::sharder::get_md5_shard; use crate::ufc::{Assignment, AssignmentValue, VariationType}; -use crate::{ArcStr, Configuration, EvaluationError}; +use crate::{Configuration, EvaluationError, Str}; use crate::{ContextAttributes, SdkMetadata}; use super::eval_assignment::get_assignment_with_visitor; @@ -37,7 +37,7 @@ struct Action<'a> { #[derive(Debug, Clone, Serialize)] pub struct BanditResult { /// Selected variation from the feature flag. - pub variation: ArcStr, + pub variation: Str, /// Selected action if any. pub action: Option, /// Flag assignment event that needs to be logged to analytics storage. @@ -51,10 +51,10 @@ pub struct BanditResult { pub fn get_bandit_action( configuration: Option<&Configuration>, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &ContextAttributes, actions: &HashMap, - default_variation: &ArcStr, + default_variation: &Str, now: DateTime, sdk_meta: &SdkMetadata, ) -> BanditResult { @@ -76,10 +76,10 @@ pub fn get_bandit_action( pub fn get_bandit_action_details( configuration: Option<&Configuration>, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &ContextAttributes, actions: &HashMap, - default_variation: &ArcStr, + default_variation: &Str, now: DateTime, sdk_meta: &SdkMetadata, ) -> (BanditResult, EvaluationDetails) { @@ -110,10 +110,10 @@ fn get_bandit_action_with_visitor( visitor: &mut V, configuration: Option<&Configuration>, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &ContextAttributes, actions: &HashMap, - default_variation: &ArcStr, + default_variation: &Str, now: DateTime, sdk_meta: &SdkMetadata, ) -> BanditResult { @@ -410,22 +410,22 @@ mod tests { use serde::{Deserialize, Serialize}; use crate::{ - eval::get_bandit_action, ufc::UniversalFlagConfig, ArcStr, Configuration, - ContextAttributes, SdkMetadata, + eval::get_bandit_action, ufc::UniversalFlagConfig, Configuration, ContextAttributes, + SdkMetadata, Str, }; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct TestFile { flag: String, - default_value: ArcStr, + default_value: Str, subjects: Vec, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct TestSubject { - subject_key: ArcStr, + subject_key: Str, subject_attributes: TestContextAttributes, actions: Vec, assignment: TestAssignment, @@ -435,7 +435,7 @@ mod tests { #[serde(rename_all = "camelCase")] struct TestContextAttributes { numeric_attributes: HashMap, - categorical_attributes: HashMap, + categorical_attributes: HashMap, } impl From for ContextAttributes { fn from(value: TestContextAttributes) -> ContextAttributes { @@ -457,7 +457,7 @@ mod tests { #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "camelCase")] struct TestAssignment { - variation: ArcStr, + variation: Str, action: Option, } diff --git a/eppo_core/src/eval/eval_details.rs b/eppo_core/src/eval/eval_details.rs index fe0bd0b9..c52516ff 100644 --- a/eppo_core/src/eval/eval_details.rs +++ b/eppo_core/src/eval/eval_details.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{EvaluationError, EvaluationFailure}, ufc::{AssignmentValue, ConditionWire, Shard}, - ArcStr, AttributeValue, Attributes, + AttributeValue, Attributes, Str, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] @@ -68,7 +68,7 @@ impl EvaluationResultWithDetails { #[serde(rename_all = "camelCase")] pub struct EvaluationDetails { pub flag_key: String, - pub subject_key: ArcStr, + pub subject_key: Str, pub subject_attributes: Arc, /// Timestamp when the flag was evaluated. pub timestamp: DateTime, @@ -80,14 +80,14 @@ pub struct EvaluationDetails { /// fetched yet. pub config_published_at: Option>, /// Environment the configuration belongs to. None if configuration hasn't been fetched yet. - pub environment_name: Option, + pub environment_name: Option, pub bandit_evaluation_code: Option, pub flag_evaluation_code: Option, pub flag_evaluation_description: String, /// Key of the selected variation. - pub variation_key: Option, + pub variation_key: Option, /// Value of the selected variation. Could be `None` if no variation is selected, or selected /// value is absent in configuration (configuration error). pub variation_value: Option, @@ -102,7 +102,7 @@ pub struct EvaluationDetails { #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] pub struct AllocationEvaluationDetails { - pub key: ArcStr, + pub key: Str, /// Order position of the allocation as seen in the Web UI. pub order_position: usize, pub allocation_evaluation_code: AllocationEvaluationCode, @@ -145,7 +145,7 @@ pub struct ConditionEvaluationDetails { #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] pub struct SplitEvaluationDetails { - pub variation_key: ArcStr, + pub variation_key: Str, pub matched: bool, pub shards: Vec, } diff --git a/eppo_core/src/eval/eval_details_builder.rs b/eppo_core/src/eval/eval_details_builder.rs index 80e28068..302598e5 100644 --- a/eppo_core/src/eval/eval_details_builder.rs +++ b/eppo_core/src/eval/eval_details_builder.rs @@ -5,7 +5,7 @@ use chrono::{DateTime, Utc}; use crate::{ error::EvaluationFailure, ufc::{Allocation, Assignment, AssignmentValue, Condition, Flag, RuleWire, Shard, Split}, - ArcStr, AttributeValue, Attributes, Configuration, EvaluationError, + AttributeValue, Attributes, Configuration, EvaluationError, Str, }; use super::{ @@ -18,16 +18,16 @@ use super::{ /// It works with both assignment and bandit evaluation. pub(crate) struct EvalDetailsBuilder { flag_key: String, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Arc, now: DateTime, configuration_fetched_at: Option>, configuration_published_at: Option>, - environment_name: Option, + environment_name: Option, flag_evaluation_failure: Option>, - variation_key: Option, + variation_key: Option, variation_value: Option, bandit_evaluation_failure: Option>, @@ -38,8 +38,8 @@ pub(crate) struct EvalDetailsBuilder { matched_details: Option, /// List of allocation keys. Used to sort `allocation_eval_results`. - allocation_keys_order: Vec, - allocation_eval_results: HashMap, + allocation_keys_order: Vec, + allocation_eval_results: HashMap, } /// Interim struct to construct `flag_evaluation_details` later. @@ -54,7 +54,7 @@ pub(crate) struct EvalAllocationDetailsBuilder<'a> { allocation_is_experiment: bool, matched: &'a mut Option, allocation_details: &'a mut AllocationEvaluationDetails, - variation_key: &'a mut Option, + variation_key: &'a mut Option, } pub(crate) struct EvalRuleDetailsBuilder<'a> { @@ -68,7 +68,7 @@ pub(crate) struct EvalSplitDetailsBuilder<'a> { impl EvalDetailsBuilder { pub fn new( flag_key: String, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Arc, now: DateTime, ) -> EvalDetailsBuilder { diff --git a/eppo_core/src/eval/evaluator.rs b/eppo_core/src/eval/evaluator.rs index 7a91bc1d..431d3f86 100644 --- a/eppo_core/src/eval/evaluator.rs +++ b/eppo_core/src/eval/evaluator.rs @@ -6,7 +6,7 @@ use crate::{ configuration_store::ConfigurationStore, events::AssignmentEvent, ufc::{Assignment, AssignmentValue, VariationType}, - ArcStr, Attributes, Configuration, ContextAttributes, EvaluationError, SdkMetadata, + Attributes, Configuration, ContextAttributes, EvaluationError, SdkMetadata, Str, }; use super::{ @@ -34,7 +34,7 @@ impl Evaluator { pub fn get_assignment( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, ) -> Result, EvaluationError> { @@ -52,7 +52,7 @@ impl Evaluator { pub fn get_assignment_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, ) -> ( @@ -73,10 +73,10 @@ impl Evaluator { pub fn get_bandit_action( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &ContextAttributes, actions: &HashMap, - default_variation: &ArcStr, + default_variation: &Str, ) -> BanditResult { let configuration = self.get_configuration(); get_bandit_action( @@ -94,10 +94,10 @@ impl Evaluator { pub fn get_bandit_action_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &ContextAttributes, actions: &HashMap, - default_variation: &ArcStr, + default_variation: &Str, ) -> (BanditResult, EvaluationDetails) { let configuration = self.get_configuration(); get_bandit_action_details( diff --git a/eppo_core/src/events.rs b/eppo_core/src/events.rs index b5e685ae..b8fcbafb 100644 --- a/eppo_core/src/events.rs +++ b/eppo_core/src/events.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::Arc}; use serde::Serialize; -use crate::{eval::eval_details::EvaluationDetails, ArcStr, Attributes, SdkMetadata}; +use crate::{eval::eval_details::EvaluationDetails, Attributes, SdkMetadata, Str}; /// Events that can be emitted during evaluation of assignment or bandit. They need to be logged to /// analytics storage and fed back to Eppo for analysis. @@ -18,13 +18,13 @@ pub struct Events { #[serde(rename_all = "camelCase")] pub struct AssignmentEventBase { /// The key of the feature flag being assigned. - pub feature_flag: ArcStr, + pub feature_flag: Str, /// The key of the allocation that the subject was assigned to. - pub allocation: ArcStr, + pub allocation: Str, /// The key of the experiment associated with the assignment. pub experiment: String, /// The specific variation assigned to the subject. - pub variation: ArcStr, + pub variation: Str, /// Additional metadata such as SDK language and version. pub meta_data: EventMetaData, /// Additional user-defined logging fields for capturing extra information related to the @@ -40,7 +40,7 @@ pub struct AssignmentEventBase { pub struct AssignmentEvent { pub base: Arc, /// The key identifying the subject receiving the assignment. - pub subject: ArcStr, + pub subject: Str, /// Custom attributes of the subject relevant to the assignment. pub subject_attributes: Arc, /// The timestamp indicating when the assignment event occurred. @@ -57,16 +57,16 @@ pub struct AssignmentEvent { pub struct BanditEvent { pub flag_key: String, pub bandit_key: String, - pub subject: ArcStr, + pub subject: Str, pub action: String, pub action_probability: f64, pub optimality_gap: f64, pub model_version: String, pub timestamp: String, pub subject_numeric_attributes: HashMap, - pub subject_categorical_attributes: HashMap, + pub subject_categorical_attributes: HashMap, pub action_numeric_attributes: HashMap, - pub action_categorical_attributes: HashMap, + pub action_categorical_attributes: HashMap, pub meta_data: EventMetaData, } diff --git a/eppo_core/src/lib.rs b/eppo_core/src/lib.rs index 725b5709..8e72352b 100644 --- a/eppo_core/src/lib.rs +++ b/eppo_core/src/lib.rs @@ -72,4 +72,4 @@ pub use configuration::Configuration; pub use context_attributes::ContextAttributes; pub use error::{Error, EvaluationError, Result}; pub use sdk_metadata::SdkMetadata; -pub use str::ArcStr; +pub use str::Str; diff --git a/eppo_core/src/str.rs b/eppo_core/src/str.rs index 46ac5aaa..b64d49bc 100644 --- a/eppo_core/src/str.rs +++ b/eppo_core/src/str.rs @@ -8,18 +8,19 @@ use faststr::FastStr; use serde::{Deserialize, Serialize}; -/// `ArcStr` is a string that can be cloned cheaply. +/// `Str` is a string optimized for cheap cloning. The implementation is hidden, so we can update it +/// if we find faster implementation. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] #[serde(transparent)] -pub struct ArcStr(FastStr); +pub struct Str(FastStr); -impl ArcStr { - pub fn new>(s: S) -> ArcStr { - ArcStr(FastStr::new(s)) +impl Str { + pub fn new>(s: S) -> Str { + Str(FastStr::new(s)) } - pub fn from_static_str(s: &'static str) -> ArcStr { - ArcStr(FastStr::from_static_str(s)) + pub fn from_static_str(s: &'static str) -> Str { + Str(FastStr::from_static_str(s)) } pub fn as_str(&self) -> &str { @@ -27,13 +28,13 @@ impl ArcStr { } } -impl std::fmt::Debug for ArcStr { +impl std::fmt::Debug for Str { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self.0) } } -impl std::fmt::Display for ArcStr { +impl std::fmt::Display for Str { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(&self.0) } @@ -41,9 +42,9 @@ impl std::fmt::Display for ArcStr { macro_rules! impl_from_faststr { ($ty:ty) => { - impl From<$ty> for ArcStr { - fn from(value: $ty) -> ArcStr { - ArcStr(value.into()) + impl From<$ty> for Str { + fn from(value: $ty) -> Str { + Str(value.into()) } } }; @@ -52,16 +53,15 @@ macro_rules! impl_from_faststr { impl_from_faststr!(Arc); impl_from_faststr!(Arc); impl_from_faststr!(String); -impl_from_faststr!(FastStr); -impl<'a> From<&'a str> for ArcStr { - fn from(value: &'a str) -> ArcStr { - ArcStr(FastStr::new(value)) +impl<'a> From<&'a str> for Str { + fn from(value: &'a str) -> Str { + Str(FastStr::new(value)) } } -impl<'a> From> for ArcStr { - fn from(value: Cow<'a, str>) -> ArcStr { +impl<'a> From> for Str { + fn from(value: Cow<'a, str>) -> Str { match value { Cow::Borrowed(s) => s.into(), Cow::Owned(s) => s.into(), @@ -69,13 +69,13 @@ impl<'a> From> for ArcStr { } } -impl AsRef for ArcStr { +impl AsRef for Str { fn as_ref(&self) -> &str { &self.0 } } -impl std::ops::Deref for ArcStr { +impl std::ops::Deref for Str { type Target = str; fn deref(&self) -> &Self::Target { @@ -83,7 +83,7 @@ impl std::ops::Deref for ArcStr { } } -impl log::kv::ToValue for ArcStr { +impl log::kv::ToValue for Str { fn to_value(&self) -> log::kv::Value { log::kv::Value::from_display(self) } @@ -96,15 +96,15 @@ mod pyo3_impl { use pyo3::prelude::*; use pyo3::types::PyString; - use crate::ArcStr; + use crate::Str; - impl<'py> FromPyObject<'py> for ArcStr { + impl<'py> FromPyObject<'py> for Str { fn extract_bound(value: &Bound<'py, PyAny>) -> PyResult { - Ok(ArcStr::from(value.extract::>()?)) + Ok(Str::from(value.extract::>()?)) } } - impl ToPyObject for ArcStr { + impl ToPyObject for Str { fn to_object(&self, py: Python<'_>) -> PyObject { PyString::new_bound(py, &self).into() } diff --git a/eppo_core/src/ufc/assignment.rs b/eppo_core/src/ufc/assignment.rs index ca20395e..594472d0 100644 --- a/eppo_core/src/ufc/assignment.rs +++ b/eppo_core/src/ufc/assignment.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use serde::{Deserialize, Serialize}; -use crate::{events::AssignmentEvent, ArcStr}; +use crate::{events::AssignmentEvent, Str}; /// Result of assignment evaluation. #[derive(Debug, Serialize, Clone)] @@ -19,7 +19,7 @@ pub struct Assignment { #[serde(tag = "type", content = "value", rename_all = "SCREAMING_SNAKE_CASE")] pub enum AssignmentValue { /// A string value. - String(ArcStr), + String(Str), /// An integer value. Integer(i64), /// A numeric value (floating-point). @@ -74,7 +74,7 @@ impl AssignmentValue { /// let value = AssignmentValue::String("example".into()); /// assert_eq!(value.to_string(), Some("example".into())); /// ``` - pub fn to_string(self) -> Option { + pub fn to_string(self) -> Option { match self { AssignmentValue::String(s) => Some(s), _ => None, diff --git a/eppo_core/src/ufc/compiled_flag_config.rs b/eppo_core/src/ufc/compiled_flag_config.rs index 929e68a6..225e1b05 100644 --- a/eppo_core/src/ufc/compiled_flag_config.rs +++ b/eppo_core/src/ufc/compiled_flag_config.rs @@ -6,7 +6,7 @@ use crate::{ error::EvaluationFailure, events::{AssignmentEventBase, EventMetaData}, sharder::PreSaltedSharder, - ArcStr, Error, EvaluationError, SdkMetadata, + Error, EvaluationError, SdkMetadata, Str, }; use super::{ @@ -47,7 +47,7 @@ pub(crate) struct Flag { #[derive(Debug)] pub(crate) struct Allocation { - pub key: ArcStr, // key is here to support evaluation details + pub key: Str, // key is here to support evaluation details pub start_at: Option, pub end_at: Option, pub rules: Box<[RuleWire]>, @@ -57,7 +57,7 @@ pub(crate) struct Allocation { #[derive(Debug)] pub(crate) struct Split { pub shards: Vec, - pub variation_key: ArcStr, // for evaluation details + pub variation_key: Str, // for evaluation details // This is a Result because it may still return a configuration error (invalid value for // assignment type). pub result: Result<(AssignmentValue, Option>), EvaluationFailure>, @@ -172,9 +172,9 @@ fn compile_flag(meta_data: EventMetaData, flag: FlagWire) -> Flag { fn compile_allocation( meta_data: EventMetaData, - flag_key: &ArcStr, + flag_key: &Str, allocation: AllocationWire, - variation_values: &HashMap>, + variation_values: &HashMap>, total_shards: u32, ) -> Allocation { let splits = allocation @@ -203,10 +203,10 @@ fn compile_allocation( fn compile_split( meta_data: EventMetaData, - flag_key: &ArcStr, - allocation_key: &ArcStr, + flag_key: &Str, + allocation_key: &Str, split: SplitWire, - variation_values: &HashMap>, + variation_values: &HashMap>, total_shards: u32, do_log: bool, ) -> Split { diff --git a/eppo_core/src/ufc/models.rs b/eppo_core/src/ufc/models.rs index 1704c117..1c2d5c98 100644 --- a/eppo_core/src/ufc/models.rs +++ b/eppo_core/src/ufc/models.rs @@ -5,7 +5,7 @@ use regex::Regex; use semver::Version; use serde::{Deserialize, Serialize}; -use crate::{ArcStr, Error, EvaluationError}; +use crate::{Error, EvaluationError, Str}; use super::AssignmentValue; @@ -35,7 +35,7 @@ pub(crate) struct UniversalFlagConfigWire { #[serde(rename_all = "camelCase")] pub(crate) struct Environment { /// Name of the environment. - pub name: ArcStr, + pub name: Str, } /// `TryParse` allows the subfield to fail parsing without failing the parsing of the whole @@ -77,7 +77,7 @@ impl<'a, T> From<&'a TryParse> for Option<&'a T> { #[serde(rename_all = "camelCase")] #[allow(missing_docs)] pub(crate) struct FlagWire { - pub key: ArcStr, + pub key: Str, pub enabled: bool, pub variation_type: VariationType, pub variations: HashMap, @@ -109,7 +109,7 @@ pub(crate) enum ValueWire { /// Number maps to either [`AssignmentValue::Integer`] or [`AssignmentValue::Numeric`]. Number(f64), /// String maps to either [`AssignmentValue::String`] or [`AssignmentValue::Json`]. - String(ArcStr), + String(Str), } impl ValueWire { @@ -148,7 +148,7 @@ impl ValueWire { } } - fn into_string(self) -> Option { + fn into_string(self) -> Option { match self { Self::String(value) => Some(value), _ => None, @@ -165,7 +165,7 @@ impl ValueWire { #[serde(rename_all = "camelCase")] #[allow(missing_docs)] pub(crate) struct VariationWire { - pub key: ArcStr, + pub key: Str, pub value: ValueWire, } @@ -173,7 +173,7 @@ pub(crate) struct VariationWire { #[serde(rename_all = "camelCase")] #[allow(missing_docs)] pub(crate) struct AllocationWire { - pub key: ArcStr, + pub key: Str, #[serde(default)] pub rules: Box<[RuleWire]>, #[serde(default)] @@ -287,7 +287,7 @@ impl From for ConditionWire { } else { ConditionOperator::NotMatches }, - ConditionValue::Single(ValueWire::String(ArcStr::from(regex.as_str()))), + ConditionValue::Single(ValueWire::String(Str::from(regex.as_str()))), ), ConditionCheck::Membership { expected_membership, @@ -482,7 +482,7 @@ impl From> for ConditionValue { #[allow(missing_docs)] pub(crate) struct SplitWire { pub shards: Vec, - pub variation_key: ArcStr, + pub variation_key: Str, #[serde(default)] pub extra_logging: HashMap, } diff --git a/python-sdk/src/client.rs b/python-sdk/src/client.rs index ca5d2719..4da0e4f9 100644 --- a/python-sdk/src/client.rs +++ b/python-sdk/src/client.rs @@ -27,7 +27,7 @@ use eppo_core::{ poller_thread::{PollerThread, PollerThreadConfig}, pyo3::TryToPyObject, ufc::VariationType, - ArcStr, Attributes, ContextAttributes, + Attributes, ContextAttributes, Str, }; use crate::{ @@ -152,7 +152,7 @@ impl EppoClient { fn get_string_assignment( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -168,7 +168,7 @@ impl EppoClient { fn get_integer_assignment( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -184,7 +184,7 @@ impl EppoClient { fn get_numeric_assignment( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -200,7 +200,7 @@ impl EppoClient { fn get_boolean_assignment( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -216,7 +216,7 @@ impl EppoClient { fn get_json_assignment( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: PyObject, ) -> PyResult { @@ -233,7 +233,7 @@ impl EppoClient { fn get_string_assignment_details( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -249,7 +249,7 @@ impl EppoClient { fn get_integer_assignment_details( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -265,7 +265,7 @@ impl EppoClient { fn get_numeric_assignment_details( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -281,7 +281,7 @@ impl EppoClient { fn get_boolean_assignment_details( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -297,7 +297,7 @@ impl EppoClient { fn get_json_assignment_details( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, default: Py, ) -> PyResult { @@ -363,13 +363,13 @@ impl EppoClient { fn get_bandit_action( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, #[pyo3(from_py_with = "context_attributes_from_py")] subject_context: RefOrOwned< ContextAttributes, PyRef, >, #[pyo3(from_py_with = "actions_from_py")] actions: HashMap, - default: ArcStr, + default: Str, ) -> PyResult { let py = slf.py(); let this = slf.get(); @@ -396,13 +396,13 @@ impl EppoClient { fn get_bandit_action_details( slf: &Bound, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, #[pyo3(from_py_with = "context_attributes_from_py")] subject_context: RefOrOwned< ContextAttributes, PyRef, >, #[pyo3(from_py_with = "actions_from_py")] actions: HashMap, - default: ArcStr, + default: Str, ) -> PyResult { let py = slf.py(); let this = slf.get(); @@ -610,7 +610,7 @@ impl EppoClient { &self, py: Python, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, expected_type: Option, default: Py, @@ -650,7 +650,7 @@ impl EppoClient { &self, py: Python, flag_key: &str, - subject_key: ArcStr, + subject_key: Str, subject_attributes: Attributes, expected_type: Option, default: Py, diff --git a/rust-sdk/src/client.rs b/rust-sdk/src/client.rs index 42fdf94d..ee70c1a1 100644 --- a/rust-sdk/src/client.rs +++ b/rust-sdk/src/client.rs @@ -10,7 +10,7 @@ use eppo_core::{ configuration_store::ConfigurationStore, eval::{Evaluator, EvaluatorConfig}, ufc::{Assignment, VariationType}, - ArcStr, + Str, }; /// A client for Eppo API. @@ -112,7 +112,7 @@ impl<'a> Client<'a> { pub fn get_assignment( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> Result, EvaluationError> { self.get_assignment_inner(flag_key, subject_key, subject_attributes, None, |x| x) @@ -145,9 +145,9 @@ impl<'a> Client<'a> { pub fn get_string_assignment( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, - ) -> Result, EvaluationError> { + ) -> Result, EvaluationError> { self.get_assignment_inner( flag_key, subject_key, @@ -188,7 +188,7 @@ impl<'a> Client<'a> { pub fn get_integer_assignment( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> Result, EvaluationError> { self.get_assignment_inner( @@ -231,7 +231,7 @@ impl<'a> Client<'a> { pub fn get_numeric_assignment( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> Result, EvaluationError> { self.get_assignment_inner( @@ -274,7 +274,7 @@ impl<'a> Client<'a> { pub fn get_boolean_assignment( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> Result, EvaluationError> { self.get_assignment_inner( @@ -318,7 +318,7 @@ impl<'a> Client<'a> { pub fn get_json_assignment( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> Result>, EvaluationError> { self.get_assignment_inner( @@ -337,7 +337,7 @@ impl<'a> Client<'a> { fn get_assignment_inner( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, convert: impl FnOnce(AssignmentValue) -> T, @@ -385,7 +385,7 @@ impl<'a> Client<'a> { pub fn get_assignment_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> EvaluationResultWithDetails { self.get_assignment_details_inner(flag_key, subject_key, subject_attributes, None) @@ -399,9 +399,9 @@ impl<'a> Client<'a> { pub fn get_string_assignment_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, - ) -> EvaluationResultWithDetails { + ) -> EvaluationResultWithDetails { self.get_assignment_details_inner( flag_key, subject_key, @@ -422,7 +422,7 @@ impl<'a> Client<'a> { pub fn get_integer_assignment_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> EvaluationResultWithDetails { self.get_assignment_details_inner( @@ -445,7 +445,7 @@ impl<'a> Client<'a> { pub fn get_numeric_assignment_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> EvaluationResultWithDetails { self.get_assignment_details_inner( @@ -468,7 +468,7 @@ impl<'a> Client<'a> { pub fn get_boolean_assignment_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> EvaluationResultWithDetails { self.get_assignment_details_inner( @@ -491,7 +491,7 @@ impl<'a> Client<'a> { pub fn get_json_assignment_details( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, ) -> EvaluationResultWithDetails> { self.get_assignment_details_inner( @@ -509,7 +509,7 @@ impl<'a> Client<'a> { fn get_assignment_details_inner( &self, flag_key: &str, - subject_key: &ArcStr, + subject_key: &Str, subject_attributes: &Arc, expected_type: Option, ) -> EvaluationResultWithDetails {