Skip to main content

native/kameleoon_elixir_bridge/src/rule_ex.rs

use std::collections::HashMap;

use kameleoon_core::types::Rule as TypesRule;

use crate::{utils_ex::ArcStr, variation_ex::VariationEx};

#[derive(Debug, rustler::NifStruct)]
#[module = "Kameleoon.Types.Rule"]
#[rustler(encode)]
pub(crate) struct RuleEx {
    variations: HashMap<ArcStr, VariationEx>,
}

impl From<&TypesRule> for RuleEx {
    fn from(value: &TypesRule) -> Self {
        Self {
            variations: value
                .variations
                .iter()
                .map(|(key, variation)| (key.clone().into(), variation.into()))
                .collect(),
        }
    }
}