Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abrarnitk/rust_elm_types
Repository that converts Rust struct to Elm Types
https://github.com/abrarnitk/rust_elm_types
autodecoder autoencoder autogenerated elm rust rusttoelmtypes
Last synced: 22 days ago
JSON representation
Repository that converts Rust struct to Elm Types
- Host: GitHub
- URL: https://github.com/abrarnitk/rust_elm_types
- Owner: AbrarNitk
- License: mit
- Created: 2019-09-05T18:43:05.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-10T09:18:40.000Z (over 5 years ago)
- Last Synced: 2024-11-16T05:24:44.968Z (about 2 months ago)
- Topics: autodecoder, autoencoder, autogenerated, elm, rust, rusttoelmtypes
- Language: Rust
- Size: 31.3 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust to Elm Type Generator
### This repo contains simple rust struct to elm type generator.## Examples
1. File Path may be set into env variable called (ELM_TYPES).
2. File path may be passed as elm options, this will override env path.- ### Example 1
- #### struct with option path(path is mandatory option)
```rust
#[macro_use]
extern crate elm_rusty;// Declare struct with Elm derive
// Here path is mandatory in elm opts or export in env variable as ELM_TYPES
#[derive(Elm)]
#[elm(opts(path = "/Users/abrarkhan/Documents/github/rust_elm_types"))]
struct Foo {
id: i32,
name: String,
}
```
After change into models, When ever run cargo build, check or test first time it will generated corresponding Elm code.```elm
module Foo exposing (..)type alias Foo =
{ id: Int
, name: String
}```
- ### Example 2
- #### struct with option path and rename
```rust
#[macro_use]
extern crate elm_rusty;mod temp {
pub struct User {}
}#[derive(Elm)]
#[elm(opts(rename = "ElmUser", path = "/Users/abrarkhan/Documents/github/rust_elm_types"))]
struct User {
name: Option>,
id: Vec>>,
vector: Vec,
}
``````elm
module ElmUser exposing (..)type alias ElmUser =
{ vector: List Int
, name: Maybe(List Int)
, id: List(Dict String(List User))
}```
## Note Point
Here, I did not handle recursively custom type derive Elm, so it won't create corresponding User.elm- ### Example 3
- #### struct with option path, elm type rename and field rename option
```rust
#[macro_use]
extern crate elm_rusty;mod temp {
pub struct User {}
}#[derive(Elm)]
#[elm(opts(rename = "ElmUser", path = "/Users/abrarkhan/Documents/github/rust_elm_types"))]
struct User {
#[elm(rename = "foo")]
name: Option>,
id: Vec>>,
vector: Vec,
}
``````elm
module ElmUser exposing (..)
type alias ElmUser =
{ id: List(Dict String(List User))
, foo: Maybe(List Int)
, vector: List Int
}```
- ### Example 4
- #### struct(reference types) with option path, elm type rename and field rename option
```rust#[macro_use]
extern crate elm_rusty;mod temp {
pub struct User {}
}#[derive(Elm)]
#[elm(opts(rename = "ElmUser", path = "/Users/abrarkhan/Documents/github/rust_elm_types"))]
struct User<'a> {
#[elm(rename = "foo")]
name: Option>,
id: &'a Vec>>,
vector: Vec,
}
``````elm
module ElmUser exposing (..)
type alias ElmUser =
{ id: List(Dict String(List User))
, foo: Maybe(List Int)
, vector: List Int
}```
- ### Example 5
- #### without elm options and export path as ELM_TYPES="/Users/abrarkhan/Documents/github/rust_elm_types"
```rust#[macro_use]
extern crate elm_rusty;mod temp {
pub struct User {}
}#[derive(Elm)]
struct User<'a> {
#[elm(rename = "foo")]
name: Option>,
id: &'a Vec>>,
vector: Vec,
}
``````elm
module User exposing (..)
type alias User =
{ id: List(Dict String(List User))
, foo: Maybe(List Int)
, vector: List Int
}```
# RoadMap
* [x] Generate Elm types alias from Rust struct.
* [ ] Make recursively type checks.
* [ ] Auto Import of Elm modules, if it exists inside same dir.
* [ ] Generate Elm types from Rust types.
* [ ] Generate Elm encoders from Rust types.
* [ ] Generate Elm decoders from Rust types.