Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement derive macro to automatically convert Value to T #21

Open
sheepduke opened this issue Sep 15, 2023 · 5 comments
Open

Implement derive macro to automatically convert Value to T #21

sheepduke opened this issue Sep 15, 2023 · 5 comments
Labels
good first issue Good for newcomers

Comments

@sheepduke
Copy link
Contributor

Automatically implement From<StructValue> for T with derive macro.

@sheepduke sheepduke added the good first issue Good for newcomers label Sep 15, 2023
@gruebel
Copy link
Member

gruebel commented Jan 6, 2024

hey @sheepduke could you share more details for this task, I would be interested to contribute, but not sure what exactly is asked for 😅

@sheepduke
Copy link
Contributor Author

sheepduke commented Jan 8, 2024

hey @sheepduke could you share more details for this task, I would be interested to contribute, but not sure what exactly is asked for 😅

@gruebel Sure! You see, we have a function get_struct_value defined in the client.rs file. It is used to return a structure as required by the specification. The caller is able to pass in a type parameter T and this function will return corresponding type, as long as T implements TryFrom<StructValue>. Here StructValue is a variant of enum Value that we use to represent the structure internally, similar to how serde_json handles this.

Now to really make use of this function, the caller needs to manually implement TryFrom<StructValue> for their custom type, unless they just want StructValue. This is not convenient, if ever useful.

My idea is to implement something similar to serde. The consumer can simply derive something when defining their custom types, and the corresponding impl TryFrom<StructValue> and/or impl TryFrom<&StructValue> code is automatically generated.

Further more, you may have noticed that there is a feature serde_json that implements TryFrom<serde_json::Value> and TryFrom<&serde_json::Value> for our own Value. We may add another feature serde that generate corresponding code for type T when T derives serde. So, the consumer can simply enable this feature and all the custom types that have serde serialization defined can automatically supported like get_struct_value<MyType>.

These are just my brief ideas. Please feel free to ask any question and/or propose your ideas here. :-)

@gruebel
Copy link
Member

gruebel commented Jan 9, 2024

Thanks, definitely will give it a try 💪

@gruebel
Copy link
Member

gruebel commented Jan 28, 2024

hey @sheepduke I finally had some time to look into it and as far as I understand it, we would need to create a separate crate to implement a procedural macro. If we want to go that way, we should first change the project to leverage a workspace and then create a new package open-feature-derive. WDYT?

@sheepduke
Copy link
Contributor Author

sheepduke commented Feb 13, 2024

hey @sheepduke I finally had some time to look into it and as far as I understand it, we would need to create a separate crate to implement a procedural macro. If we want to go that way, we should first change the project to leverage a workspace and then create a new package open-feature-derive. WDYT?

Strange. I thought I replied your message via email but it seemed not. My bad. :-(

I am absolutely fine with it, especially when there is not another choice...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants