1
Fork 0
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:
Steffo 2024-01-02 06:52:17 +01:00
parent a6f08368b4
commit 9a12a03e62
Signed by: steffo
GPG key ID: 2A24051445686895

View file

@ -65,41 +65,38 @@ pub fn config(input: TokenStream) -> TokenStream {
let identifier = item.identifier;
// TODO: Can types be zero-length?
let mut conversion_code = quote! {};
let mut previous_conversion: Option<&Conversion> = None;
for pair in item.types.pairs().into_iter() {
if let Some(some_conversion) = previous_conversion {
todo!();
let mut current_type: &Type = match pair {
Pair::Punctuated(ty, _) => ty,
Pair::End(ty) => ty,
};
let next_conversion: Option<&Conversion> = match pair {
Pair::Punctuated(_, cv) => Some(cv),
_ => None,
};
match pair {
Pair::Punctuated(target_type, new_conversion) => {
previous_conversion = Some(new_conversion);
}
Pair::End(target_type) => {
}
}
conversion_code = match some_conversion {
if let Some(previous_conversion) = previous_conversion {
conversion_code = match previous_conversion {
Conversion::From => quote! {
#conversion_code
let value: #target_type = value.into();
let value: #current_type = value.into();
}
Conversion::TryFrom => quote! {
#conversion_code
let value: #target_type = value.try_into()
let value: #current_type = value.try_into()
.expect("to be able to convert {}", stringify!(#identifier));
}
Conversion::FromStr => quote! {
#conversion_code
let value: #target_type = value.parse()
let value: #current_type = value.parse()
.expect("to be able to parse {}", stringify!(#identifier));
}
};
}
previous_conversion = next_conversion;
};
let last_type = item.types.last();