Skip to content

Generate Purescript types from your Rust types. (unmaintained)

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

tomhoule/purescript-waterslide-rs

Repository files navigation

purescript-waterslide-rs

travis badge crates.io badge docs.rs badge

logo

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 implementing AsPursType 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's Display 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

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.

About

Generate Purescript types from your Rust types. (unmaintained)

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages