Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

feat: add vec supporting #25

Merged
merged 4 commits into from
Apr 22, 2021
Merged

feat: add vec supporting #25

merged 4 commits into from
Apr 22, 2021

Conversation

pleshevskiy
Copy link
Owner

I've added support for Vec type.

  • added functions to read env var into the Vec
  • added support in macro

See full example bellow

extern crate itconfig;
use itconfig::*;
use std::env;

#[derive(Debug, PartialEq, Eq)]
enum PaymentPlatform {
    PayPal,
    Stripe,
    SomethingElse,
}

impl FromEnvString for PaymentPlatform {
    type Err = &'static str;

    fn from_env_string(envstr: &EnvString) -> Result<Self, Self::Err> {
        match envstr.to_lowercase().as_str() {
            "paypal" => Ok(Self::PayPal),
            "stripe" => Ok(Self::Stripe),
            "smth" => Ok(Self::SomethingElse),
            _ => Err("Unsupported payment platform"),
        }
    }
}


fn main () {
    env::set_var("PAYMENT_PLATFORMS", "paypal,stripe");

    let payment_platforms: Option<Vec<PaymentPlatform>> = maybe_get_vec_env("PAYMENT_PLATFORMS", ",");
    assert_eq!(
        payment_platforms,
        Some(vec![PaymentPlatform::PayPal, PaymentPlatform::Stripe])
    );
}

@pleshevskiy pleshevskiy mentioned this pull request Apr 21, 2021
@pleshevskiy pleshevskiy merged commit 43eb463 into main Apr 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant