1
Fork 0
mirror of https://github.com/Steffo99/micronfig.git synced 2024-11-23 00:24:18 +00:00
micronfig/micronfig_macros/tests/sources/example_patchedporobot.rs

35 lines
1,014 B
Rust
Raw Normal View History

2024-01-04 14:30:38 +00:00
use std::str::FromStr;
2024-01-04 16:00:49 +00:00
#[derive(Debug, PartialEq, Eq)]
2024-01-04 14:30:38 +00:00
pub struct CommaSeparatedStrings(Vec<String>);
impl FromStr for CommaSeparatedStrings {
2024-01-04 16:00:49 +00:00
type Err = ();
2024-01-04 14:30:38 +00:00
fn from_str(s: &str) -> Result<Self, Self::Err> {
2024-01-04 16:00:49 +00:00
Ok(Self(s.split(',').map(|v| v.to_string()).collect()))
2024-01-04 14:30:38 +00:00
}
}
micronfig::config! {
DATA_DRAGON_LOCALE: String,
DATA_DRAGON_SET_CODES: String > crate::CommaSeparatedStrings,
POROXY_KEY: String,
POROXY_SALT: String,
SERENITY_DEV_GUILD_ID?: String > u64,
}
fn main() {
std::env::set_var("DATA_DRAGON_LOCALE", "it_IT");
std::env::set_var("DATA_DRAGON_SET_CODES", "set1,set2abc");
std::env::set_var("POROXY_KEY", "abcdef");
std::env::set_var("POROXY_SALT", "abcdef");
std::env::remove_var("SERENITY_DEV_GUILD_ID");
assert_eq!(DATA_DRAGON_LOCALE(), "it_IT");
2024-01-04 16:00:49 +00:00
assert_eq!(DATA_DRAGON_SET_CODES(), &CommaSeparatedStrings(vec!["set1".to_string(), "set2abc".to_string()]));
assert_eq!(POROXY_KEY(), "abcdef");
assert_eq!(POROXY_SALT(), "abcdef");
assert_eq!(SERENITY_DEV_GUILD_ID(), &None);
2024-01-04 14:30:38 +00:00
}