mirror of
https://github.com/Steffo99/micronfig.git
synced 2024-11-22 08:04:20 +00:00
wait this is what i wanted to do i think
This commit is contained in:
parent
a6f08368b4
commit
9a12a03e62
1 changed files with 23 additions and 26 deletions
|
@ -65,41 +65,38 @@ pub fn config(input: TokenStream) -> TokenStream {
|
||||||
let identifier = item.identifier;
|
let identifier = item.identifier;
|
||||||
|
|
||||||
// TODO: Can types be zero-length?
|
// TODO: Can types be zero-length?
|
||||||
|
|
||||||
let mut conversion_code = quote! {};
|
let mut conversion_code = quote! {};
|
||||||
|
|
||||||
let mut previous_conversion: Option<&Conversion> = None;
|
let mut previous_conversion: Option<&Conversion> = None;
|
||||||
|
|
||||||
for pair in item.types.pairs().into_iter() {
|
for pair in item.types.pairs().into_iter() {
|
||||||
if let Some(some_conversion) = previous_conversion {
|
let mut current_type: &Type = match pair {
|
||||||
todo!();
|
Pair::Punctuated(ty, _) => ty,
|
||||||
|
Pair::End(ty) => ty,
|
||||||
|
};
|
||||||
|
let next_conversion: Option<&Conversion> = match pair {
|
||||||
|
Pair::Punctuated(_, cv) => Some(cv),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
match pair {
|
if let Some(previous_conversion) = previous_conversion {
|
||||||
Pair::Punctuated(target_type, new_conversion) => {
|
conversion_code = match previous_conversion {
|
||||||
previous_conversion = Some(new_conversion);
|
|
||||||
}
|
|
||||||
Pair::End(target_type) => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
conversion_code = match some_conversion {
|
|
||||||
Conversion::From => quote! {
|
Conversion::From => quote! {
|
||||||
#conversion_code
|
#conversion_code
|
||||||
let value: #target_type = value.into();
|
let value: #current_type = value.into();
|
||||||
}
|
}
|
||||||
Conversion::TryFrom => quote! {
|
Conversion::TryFrom => quote! {
|
||||||
#conversion_code
|
#conversion_code
|
||||||
let value: #target_type = value.try_into()
|
let value: #current_type = value.try_into()
|
||||||
.expect("to be able to convert {}", stringify!(#identifier));
|
.expect("to be able to convert {}", stringify!(#identifier));
|
||||||
}
|
}
|
||||||
Conversion::FromStr => quote! {
|
Conversion::FromStr => quote! {
|
||||||
#conversion_code
|
#conversion_code
|
||||||
let value: #target_type = value.parse()
|
let value: #current_type = value.parse()
|
||||||
.expect("to be able to parse {}", stringify!(#identifier));
|
.expect("to be able to parse {}", stringify!(#identifier));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous_conversion = next_conversion;
|
||||||
};
|
};
|
||||||
|
|
||||||
let last_type = item.types.last();
|
let last_type = item.types.last();
|
||||||
|
|
Loading…
Reference in a new issue