Uneval: generate Rust code from serializable value

Greetings to fellow Rustaceans!

I've just finished the first public version of my crate uneval. This is a build-time library, used to generate Rust code for any existing value.
It can be useful, for example, if you have a large blob of data as JSON, or YAML, or something like that, and don't want to deserialize it at runtime - either it's overkill for you to use serde and friends in your crate at all, or, for example, the deserialization step seems to considerably slow down your startup time. If that's the case, you deserialize your value in the build script, pass it to the uneval, and it will generate the file which can be simply included in the expression position.

I'd like to see if someone can advise me on the result. Is the code idiomatic? Is there anything that I should try to improve? Are there any gaps in the documentation which should be filled?
Necessary links: docs.rs, github.

Thanks in advance!

4 Likes

(the first link is busted - I think you meant: https://crates.io/crates/uneval)

It's probably a good idea to mention in the docs how maps are handled, since Rust doesn't have a concept of a map literal.

Also, I note that you're currently implementing maps using into_iter on an array. That's not so great, because [_; N] doesn't impl IntoIterator yet, so this ends up autoref-ing to slice's IntoIterator.

Thanks, fixed. Not sure how I've missed this.

Noted, will do in the next version.

Not on array, but on vector. With array this wouldn't work AFAIK, since [T]::into_iter() will give iterator over &T, and we can't build owning container (be it vector or map) from references.

Ah, ok, shows what I get for hastily reading code on a phone.

I've just published the 0.2.1 version (docs are building now). Main changes:

  • Crate documentation on docs.rs now contains information on how every supported type is handled. Feel free to ask if something isn't clear, I'll try to fix.
  • Library now supports fixed-size arrays (of every size, not limited to 32 elements and including zero).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.