I do have one problem with it though. My own usecase kinda demands converting field names to UpperCamelCase, so that's what I did. It's probably not fine for everybody else, so I'm pondering what to do about it. One can put a #[rename] attribute on struct fields to rename with maximum flexibility, but that's kinda unergonomic if the default strategy is bad. What could I do here? Can I make the derive macro take an additional argument for the renaming strategy? A function &str -> String would probably give maximum flexibility, but any choice of trait from heck would probably also be fine.
Note that I could make an additional attribute alright, but as far as I can see a user would have to put it on every field anyways, so there's pretty little gain with that. Or am I missing something?
That being said, I could not understand serde's code here. I was able to extract the argument string (in your example, that would be "mod::othermod::uppercase"), but I need to make that into a function call. I have
which does what I want if I leave out the #rename(#old) and just use #old there. Of course, there would not be any renaming going on, but the above code fails with
error[E0618]: expected function, found `&'static str`
--> tests/mod.rs:4:10
|
4 | #[derive(IntoValue, Clone)]
| ^^^^^^^^^
| |
| call expression requires function
| in this derive macro expansion
|
::: /home/pips/Devel/Rust/derive_typst_intoval/src/lib.rs:52:1
|
52 | pub fn derive_into_value(item: TokenStream) -> TokenStream {
| ---------------------------------------------------------- in this expansion of `#[derive(IntoValue)]
`
For more information about this error, try `rustc --explain E0618`.
error: could not compile `derive_typst_intoval` (test "mod") due to 1 previous error