From 78c8e6c87544c300003559d2ffaeb8cfd01a13e6 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Sun, 22 Mar 2020 17:04:02 +0100 Subject: [PATCH] Adds rust demo. --- demos/rust/.gitignore | 10 ++++ demos/rust/.vscode/launch.json | 16 ++++++ demos/rust/Cargo.toml | 11 +++++ demos/rust/src/main.rs | 89 ++++++++++++++++++++++++++++++++++ extension/README.md | 1 + 5 files changed, 127 insertions(+) create mode 100644 demos/rust/.gitignore create mode 100644 demos/rust/.vscode/launch.json create mode 100644 demos/rust/Cargo.toml create mode 100644 demos/rust/src/main.rs diff --git a/demos/rust/.gitignore b/demos/rust/.gitignore new file mode 100644 index 0000000..50c8301 --- /dev/null +++ b/demos/rust/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk \ No newline at end of file diff --git a/demos/rust/.vscode/launch.json b/demos/rust/.vscode/launch.json new file mode 100644 index 0000000..f996145 --- /dev/null +++ b/demos/rust/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/target/debug/rust_demo", + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/demos/rust/Cargo.toml b/demos/rust/Cargo.toml new file mode 100644 index 0000000..f361764 --- /dev/null +++ b/demos/rust/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rust_demo" +version = "0.1.0" +authors = ["hediet"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" \ No newline at end of file diff --git a/demos/rust/src/main.rs b/demos/rust/src/main.rs new file mode 100644 index 0000000..f52ba85 --- /dev/null +++ b/demos/rust/src/main.rs @@ -0,0 +1,89 @@ +use serde::Serialize; + +#[derive(Debug, Serialize)] +struct Label { + label: Option, +} +#[derive(Debug, Serialize)] +struct Row { + label: Option, + columns: Vec, +} +#[derive(Debug, Serialize)] +struct Column { + content: Option, + tag: Option, + color: Option, +} +#[derive(Debug, Serialize)] +struct Marker { + id: String, + row: u64, + column: u64, + rows: Option, + columns: Option, + label: Option, + color: Option, +} + +#[allow(clippy::trivially_copy_pass_by_ref)] +fn is_false(b: &bool) -> bool { + !*b +} + +#[derive(Debug, Serialize)] +struct Kind { + #[serde(skip_serializing_if = "is_false")] + array: bool, +} + +#[derive(Debug, Serialize)] +pub struct Grid { + kind: Kind, + #[serde(rename = "columnLabels")] + column_labels: Option>, + rows: Vec, + markers: Option>, +} + +fn show_arr(a: &[i32]) -> String { + let n = a.len(); + let labels: Vec