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

Keyword/enum conversion using IntoValue and FromValue #35

Closed
vklquevs opened this issue Mar 28, 2018 · 3 comments
Closed

Keyword/enum conversion using IntoValue and FromValue #35

vklquevs opened this issue Mar 28, 2018 · 3 comments

Comments

@vklquevs
Copy link

vklquevs commented Mar 28, 2018

I've been thinking about treating keywords as enum values, e.g.
enum Foo { Bar, Baz } <=> :Bar and :Baz, which would be nicely derive-able.
However, a Keyword value requires a NameStore to find its string value, which means you can't IntoValue or FromValue it.

I can think of a couple of ways around this:

  • Add a Scope argument to conversion functions, so they can do a lookup if necessary
  • Change keywords to Keyword(String) in the Value enum, or add Symbol(String), to make self-representing keywords or symbols, as with similar parenthesized languages
  • Make string<->keyword conversion functions (which might be useful anyway!) that can be added in automatically by interop macros.

I'd be happy to dive in and make a PR, but each of these has trade-offs! Also, is there a better way I've not thought of?

[EDIT] Or a new EnumValue trait similar to StructValue, but I'm not sure what kind of machinery would need to go in there.

@murarth
Copy link
Owner

murarth commented Mar 28, 2018

What you're describing sounds like the value_encode module, which is enabled when you build using the serde feature. Any type implementing serde's Serialize/Deserialize traits can be converted to/from a Ketos value.

The test file shows the Ketos representation of enum values.

Is this applicable to your use case?

@vklquevs
Copy link
Author

Hey, that's neat!
I did have a more terse solution in mind, but on meditation I realized I'd have to write some glue in Ketos anyway, meaning I can just do the conversion myself. Plus, what I was describing would only really be applicable to a small subset of enum types (those without arguments), so it's not all that useful anyway.

Thanks for pointing me to that though - I can definitely use it, and sorry for the noise :)

@murarth
Copy link
Owner

murarth commented Mar 29, 2018

No need to be sorry. Glad I could help.

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

No branches or pull requests

2 participants