Skip to content

Commit

Permalink
refactor: rename ArcStr to Str
Browse files Browse the repository at this point in the history
  • Loading branch information
rasendubi committed Sep 27, 2024
1 parent cad6b1d commit a327229
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 144 deletions.
2 changes: 1 addition & 1 deletion eppo_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
Expand Down
10 changes: 5 additions & 5 deletions eppo_core/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -15,14 +15,14 @@ pub(crate) struct Subject {
}

impl Subject {
pub fn new(key: ArcStr, attributes: Arc<Attributes>) -> Subject {
pub fn new(key: Str, attributes: Arc<Attributes>) -> 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()");
};
Expand Down Expand Up @@ -74,7 +74,7 @@ pub type Attributes = HashMap<String, AttributeValue>;
pub enum AttributeValue {
/// A string value.
#[from(ignore)]
String(ArcStr),
String(Str),
/// A numerical value.
Number(f64),
/// A boolean value.
Expand All @@ -83,7 +83,7 @@ pub enum AttributeValue {
Null,
}

impl<T: Into<ArcStr>> From<T> for AttributeValue {
impl<T: Into<Str>> From<T> for AttributeValue {
fn from(value: T) -> AttributeValue {
AttributeValue::String(value.into())
}
Expand Down
8 changes: 4 additions & 4 deletions eppo_core/src/context_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<String, ArcStr>,
pub categorical: HashMap<String, Str>,
}

impl From<Attributes> for ContextAttributes {
Expand Down Expand Up @@ -82,7 +82,7 @@ mod pyo3_impl {

use pyo3::prelude::*;

use crate::{ArcStr, Attributes};
use crate::{Attributes, Str};

use super::ContextAttributes;

Expand All @@ -91,7 +91,7 @@ mod pyo3_impl {
#[new]
fn new(
numeric_attributes: HashMap<String, f64>,
categorical_attributes: HashMap<String, ArcStr>,
categorical_attributes: HashMap<String, Str>,
) -> ContextAttributes {
ContextAttributes {
numeric: numeric_attributes,
Expand Down
22 changes: 11 additions & 11 deletions eppo_core/src/eval/eval_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
Allocation, Assignment, AssignmentValue, CompiledFlagsConfig, Flag, Shard, Split,
Timestamp, VariationType,
},
ArcStr, Attributes, Configuration,
Attributes, Configuration, Str,
};

use super::{
Expand All @@ -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<Attributes>,
expected_type: Option<VariationType>,
now: DateTime<Utc>,
Expand All @@ -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<Attributes>,
expected_type: Option<VariationType>,
now: DateTime<Utc>,
Expand Down Expand Up @@ -96,7 +96,7 @@ pub(super) fn get_assignment_with_visitor<V: EvalAssignmentVisitor>(
configuration: Option<&Configuration>,
visitor: &mut V,
flag_key: &str,
subject_key: &ArcStr,
subject_key: &Str,
subject_attributes: &Arc<Attributes>,
expected_type: Option<VariationType>,
now: DateTime<Utc>,
Expand Down Expand Up @@ -163,7 +163,7 @@ impl CompiledFlagsConfig {
&self,
visitor: &mut V,
flag_key: &str,
subject_key: &ArcStr,
subject_key: &Str,
subject_attributes: &Arc<Attributes>,
expected_type: Option<VariationType>,
now: DateTime<Utc>,
Expand Down Expand Up @@ -205,7 +205,7 @@ impl Flag {
fn eval<V: EvalAssignmentVisitor>(
&self,
visitor: &mut V,
subject_key: &ArcStr,
subject_key: &Str,
subject_attributes: &Arc<Attributes>,
now: DateTime<Utc>,
) -> Result<Assignment, EvaluationFailure> {
Expand Down Expand Up @@ -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)]
Expand All @@ -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<Attributes>,
assignment: DefaultValue,
evaluation_details: TruncatedEvaluationDetails,
Expand All @@ -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<ArcStr>,
environment_name: Option<Str>,

flag_evaluation_code: TruncatedFlagEvaluationCode,
flag_evaluation_description: String,

/// Key of the selected variation.
variation_key: Option<ArcStr>,
variation_key: Option<Str>,
/// 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,
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions eppo_core/src/eval/eval_bandits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String>,
/// Flag assignment event that needs to be logged to analytics storage.
Expand All @@ -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<String, ContextAttributes>,
default_variation: &ArcStr,
default_variation: &Str,
now: DateTime<Utc>,
sdk_meta: &SdkMetadata,
) -> BanditResult {
Expand All @@ -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<String, ContextAttributes>,
default_variation: &ArcStr,
default_variation: &Str,
now: DateTime<Utc>,
sdk_meta: &SdkMetadata,
) -> (BanditResult, EvaluationDetails) {
Expand Down Expand Up @@ -110,10 +110,10 @@ fn get_bandit_action_with_visitor<V: EvalBanditVisitor>(
visitor: &mut V,
configuration: Option<&Configuration>,
flag_key: &str,
subject_key: &ArcStr,
subject_key: &Str,
subject_attributes: &ContextAttributes,
actions: &HashMap<String, ContextAttributes>,
default_variation: &ArcStr,
default_variation: &Str,
now: DateTime<Utc>,
sdk_meta: &SdkMetadata,
) -> BanditResult {
Expand Down Expand Up @@ -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<TestSubject>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct TestSubject {
subject_key: ArcStr,
subject_key: Str,
subject_attributes: TestContextAttributes,
actions: Vec<TestAction>,
assignment: TestAssignment,
Expand All @@ -435,7 +435,7 @@ mod tests {
#[serde(rename_all = "camelCase")]
struct TestContextAttributes {
numeric_attributes: HashMap<String, f64>,
categorical_attributes: HashMap<String, ArcStr>,
categorical_attributes: HashMap<String, Str>,
}
impl From<TestContextAttributes> for ContextAttributes {
fn from(value: TestContextAttributes) -> ContextAttributes {
Expand All @@ -457,7 +457,7 @@ mod tests {
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
struct TestAssignment {
variation: ArcStr,
variation: Str,
action: Option<String>,
}

Expand Down
12 changes: 6 additions & 6 deletions eppo_core/src/eval/eval_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<T> EvaluationResultWithDetails<T> {
#[serde(rename_all = "camelCase")]
pub struct EvaluationDetails {
pub flag_key: String,
pub subject_key: ArcStr,
pub subject_key: Str,
pub subject_attributes: Arc<Attributes>,
/// Timestamp when the flag was evaluated.
pub timestamp: DateTime<Utc>,
Expand All @@ -80,14 +80,14 @@ pub struct EvaluationDetails {
/// fetched yet.
pub config_published_at: Option<DateTime<Utc>>,
/// Environment the configuration belongs to. None if configuration hasn't been fetched yet.
pub environment_name: Option<ArcStr>,
pub environment_name: Option<Str>,

pub bandit_evaluation_code: Option<BanditEvaluationCode>,
pub flag_evaluation_code: Option<FlagEvaluationCode>,
pub flag_evaluation_description: String,

/// Key of the selected variation.
pub variation_key: Option<ArcStr>,
pub variation_key: Option<Str>,
/// 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<AssignmentValue>,
Expand All @@ -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,
Expand Down Expand Up @@ -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<ShardEvaluationDetails>,
}
Expand Down
Loading

0 comments on commit a327229

Please sign in to comment.