5 unstable releases
Uses old Rust 2015
0.3.1 | Aug 8, 2017 |
---|---|
0.3.0 | Aug 5, 2017 |
0.2.1 | Aug 3, 2017 |
0.2.0 | Aug 1, 2017 |
0.1.0 | Jul 30, 2017 |
#117 in #generics
26KB
598 lines
purescript-waterslide-rs
NOTE: This library is currently unmaintained. Please contact @tomhoule if you would like to do something about it.
Wouldn't it be nice if you could share your data type definitions between your Rust backend and your Purescript app? Now you can!
Waterslide generates Purescript type definitions from Rust structs and enums. It works on stable Rust.
Basic usage
- Derive Purescript representations by annotating your structs and enums with
#[derive(AsPursType)]
or by manually implementingAsPursType
if you have a custom serialization scheme. - Define a module with the
purs_module!
macro (e.g.purs_module!("Data.Dogs".to_string() ; Dachsund, ChowChow, Mutt<Void, Void>)
). - Print the module to stdout or directly to a file using
PursModule
'sDisplay
impl.
You might want to put the module generation code in a separate binary, which is easy to do with Cargo.
Important: on the Purescript side, you want to use the
Data.Argonaut.Generic.Aeson
codec to encode and decode the JSON types.
Important*: on the Rust side, your enums have to be annotated with
#[serde(tag = "tag", content = "contents")]
These restrictions will be lifted in the future by the development of an
Argonaut codec that mirrors serde_json
's defaults.
For running code, take a look at the basic example. The tests also provide a lot of usage examples, notably for generic types.
Features
- Struct and enum definitions, including tuple structs.
- Default implementations for primitive types and standard library collections (
Vec
...) - Support for generic types (e.g.
Alternative<T, U>
,Paginated<T>
...) - Whole module generation with imports
- You can define custom representations by manually implementing
AsPursType
(unstable interface)
Roadmap
Things I want to add in the coming weeks (in no particular order):
- More end to end tests to ensure JSON representation are compatible between serde_json and argonaut.
- Better documentation and examples
Acknowledgments
The idea of this library came from Haskell's purescript-bridge package.
Contributing
That would be awesome! There are no particular guidelines for pull requests (maybe in the future). We adhere to the Rust Code of Conduct.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~2MB
~48K SLoC