Skip to content

Commit a8e1a5a

Browse files
authored
Merge pull request #75 from Phrohdoh/fix-rust-demo
Fix the Rust demo
2 parents c420ff7 + d421fa1 commit a8e1a5a

File tree

3 files changed

+69
-51
lines changed

3 files changed

+69
-51
lines changed

demos/rust/.vscode/launch.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77
{
88
"type": "lldb",
99
"request": "launch",
10-
"name": "Debug",
11-
"program": "${workspaceFolder}/target/debug/rust_demo",
10+
"name": "run rust demo",
11+
"cargo": {
12+
"args": [
13+
"build",
14+
"--bin=rust_demo",
15+
"--package=rust_demo",
16+
],
17+
"filter": {
18+
"name": "rust_demo",
19+
"kind": "bin",
20+
},
21+
},
1222
"args": [],
1323
"cwd": "${workspaceFolder}"
1424
}

demos/rust/.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"debugVisualizer.debugAdapterConfigurations": {
3+
"lldb": {
4+
"expressionTemplate": "${expr}",
5+
"context": "watch"
6+
}
7+
}
8+
}

demos/rust/src/main.rs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
use serde::Serialize;
22

3+
// expected to mirror
4+
// https://hediet.github.io/visualization/docs/visualization-data-schema.json
5+
//
6+
// implements the grid visualizer as an example
7+
8+
pub type Label = String;
9+
10+
/// `GridVisualizationData` in schema
311
#[derive(Debug, Serialize)]
4-
struct Label {
5-
label: Option<String>,
6-
}
7-
#[derive(Debug, Serialize)]
8-
struct Row {
9-
label: Option<String>,
10-
columns: Vec<Column>,
12+
pub struct Grid {
13+
kind: Kind,
14+
rows: Vec<Row>,
15+
16+
#[serde(rename = "columnLabels")]
17+
#[serde(skip_serializing_if="Option::is_none")]
18+
column_labels: Option<Vec<Label>>,
1119
}
20+
1221
#[derive(Debug, Serialize)]
13-
struct Column {
14-
content: Option<String>,
15-
tag: Option<String>,
16-
color: Option<String>,
22+
pub struct Kind {
23+
grid: bool,
1724
}
25+
1826
#[derive(Debug, Serialize)]
19-
struct Marker {
20-
id: String,
21-
row: u64,
22-
column: u64,
23-
rows: Option<u64>,
24-
columns: Option<u64>,
25-
label: Option<String>,
26-
color: Option<String>,
27-
}
27+
pub struct Row {
28+
columns: Vec<Column>,
2829

29-
#[allow(clippy::trivially_copy_pass_by_ref)]
30-
fn is_false(b: &bool) -> bool {
31-
!*b
30+
#[serde(skip_serializing_if="Option::is_none")]
31+
label: Option<Label>,
3232
}
3333

3434
#[derive(Debug, Serialize)]
35-
struct Kind {
36-
#[serde(skip_serializing_if = "is_false")]
37-
array: bool,
38-
}
35+
pub struct Column {
36+
/// value to display to the user
37+
#[serde(skip_serializing_if="Option::is_none")]
38+
content: Option<String>,
3939

40-
#[derive(Debug, Serialize)]
41-
pub struct Grid {
42-
kind: Kind,
43-
#[serde(rename = "columnLabels")]
44-
column_labels: Option<Vec<Label>>,
45-
rows: Vec<Row>,
46-
markers: Option<Vec<Marker>>,
40+
/// unique value to identify this cell, if desired
41+
#[serde(skip_serializing_if="Option::is_none")]
42+
tag: Option<String>,
43+
44+
// TODO: valid values / syntax?
45+
#[serde(skip_serializing_if="Option::is_none")]
46+
color: Option<String>,
4747
}
4848

4949
fn show_arr(a: &[i32]) -> String {
50-
let n = a.len();
51-
let labels: Vec<Label> = (0..n)
52-
.map(|i| Label {
53-
label: Some(i.to_string()),
54-
})
55-
.collect();
5650
let columns: Vec<Column> = a
5751
.iter()
5852
.map(|x| Column {
5953
content: Some(format!("{:?}", x)),
60-
tag: Some(x.to_string()),
61-
color: None,
54+
tag: None,
55+
56+
// TODO: `color` value doesn't seem to change visualizer's output at all
57+
color: "who-knows".to_owned().into(),
6258
})
6359
.collect();
60+
6461
let row = Row {
65-
label: None,
6662
columns,
63+
// TODO: visualizer doesn't seem to render this
64+
label: "my row".to_owned().into(),
6765
};
68-
let kind = Kind { array: true };
66+
67+
let kind = Kind { grid: true };
6968

7069
let grid = Grid {
7170
kind,
72-
column_labels: Some(labels),
7371
rows: vec![row],
74-
markers: None,
72+
73+
// TODO: visualizer doesn't seem to work if this is non-`None`
74+
column_labels: None,
7575
};
7676

7777
serde_json::to_string(&grid).unwrap()
@@ -81,9 +81,9 @@ fn main() {
8181
let mut arr = vec![1, 2, 3];
8282
let mut _s = show_arr(&arr);
8383
for _ in 0..5 {
84-
arr.swap(0, 2); // break point
84+
arr.swap(0, 2); // set a break-point here, to easily observe the change
8585
_s = show_arr(&arr);
8686
}
87-
dbg!(arr); // break point
88-
println!("Hello, world!");
87+
dbg!(arr);
88+
println!("break-point here, too");
8989
}

0 commit comments

Comments
 (0)