1
Fork 0
mirror of https://github.com/Steffo99/micronfig.git synced 2024-11-22 16:14:19 +00:00
micronfig/micronfig_macros/tests/sources/tryfrom_single_custom.rs

20 lines
405 B
Rust
Raw Permalink Normal View History

2024-01-04 16:00:49 +00:00
#[derive(Debug, PartialEq, Eq)]
2024-01-03 03:04:57 +00:00
struct MyCustomStruct(String);
impl std::convert::TryFrom<String> for MyCustomStruct {
type Error = ();
fn try_from(value: String) -> Result<Self, Self::Error> {
Ok(Self(value))
}
}
micronfig::config! {
GARASAUTO: String => crate::MyCustomStruct,
}
fn main() {
2024-01-04 14:30:38 +00:00
std::env::set_var("GARASAUTO", "me");
2024-01-04 16:00:49 +00:00
assert_eq!(GARASAUTO(), &MyCustomStruct("me".to_string()));
2024-01-03 03:04:57 +00:00
}