-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from CADmium-Co/cleanup
Basic rust documentation and some cleanup
- Loading branch information
Showing
16 changed files
with
446 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "cadmium-api" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
cadmium = { path = "../cadmium" } | ||
|
||
[build-dependencies] | ||
convert_case = "0.6.0" | ||
cadmium = { path = "../cadmium" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::Write; | ||
|
||
use convert_case::{Case, Casing}; | ||
|
||
fn main() { | ||
let mut output = | ||
File::create(format!("{}/generated.rs", env::var("OUT_DIR").unwrap())).unwrap(); | ||
|
||
writeln!( | ||
output, | ||
"// This file is generated by build script, do not edit" | ||
) | ||
.unwrap(); | ||
|
||
let all_defs = cadmium::Project::gen_typescript_defs(); | ||
|
||
for (name, fields) in &all_defs { | ||
let iface_fields = fields.join("; "); | ||
let fn_name = name.to_case(Case::Camel); | ||
let fn_params_full = fields.join(", "); | ||
let fn_params = fn_params_full.trim_end_matches(", "); | ||
let iface_params_full = fields | ||
.iter() | ||
.map(|f| f.split(":").next().unwrap().trim()) | ||
.collect::<Vec<_>>() | ||
.join(", "); | ||
let iface_params = iface_params_full.trim_end_matches(", "); | ||
|
||
writeln!( | ||
output, | ||
r#" | ||
pub fn {fn_name}({fn_params}) -> MessageResult {{ | ||
const message: Message = {{ type: "{name}", {iface_params} }}; | ||
return sendWasmMessage(message); | ||
}}"# | ||
) | ||
.unwrap(); | ||
} | ||
|
||
let message_variants = all_defs | ||
.iter() | ||
.map(|(name, _)| format!("{{ type: \"{name}\" }} & {name}")) | ||
.collect::<Vec<_>>() | ||
.join(" | "); | ||
|
||
writeln!(output, "export type Message = {message_variants};").unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// #![allow(unused_imports)] | ||
use cadmium::feature::extrusion::{Direction, Mode}; | ||
use cadmium::isketch::ISketch; | ||
use cadmium::message::{Message, MessageResult}; | ||
use cadmium::step::StepHash; | ||
use cadmium::IDType; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/generated.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.