New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Rust #31
Comments
Which debugger do you use for rust? |
The debugger is lldb. Here is a proof of concept. use serde::Serialize;
#[derive(Debug, Serialize)]
struct Label {
label: Option<String>,
}
#[derive(Debug, Serialize)]
struct Row {
label: Option<String>,
columns: Vec<Column>,
}
#[derive(Debug, Serialize)]
struct Column {
content: Option<String>,
tag: Option<String>,
color: Option<String>,
}
#[derive(Debug, Serialize)]
struct Marker {
id: String,
row: u64,
column: u64,
rows: Option<u64>,
columns: Option<u64>,
label: Option<String>,
color: Option<String>,
}
#[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<Vec<Label>>,
rows: Vec<Row>,
markers: Option<Vec<Marker>>,
}
fn show_arr(a: &[i32]) -> String {
let n = a.len();
let labels: Vec<Label> = (0..n)
.map(|i| Label {
label: Some(i.to_string()),
})
.collect();
let columns: Vec<Column> = a
.iter()
.map(|x| Column {
content: Some(format!("{:?}", x)),
tag: Some(x.to_string()),
color: None,
})
.collect();
let row = Row {
label: None,
columns,
};
let kind = Kind { array: true };
let grid = Grid {
kind,
column_labels: Some(labels),
rows: vec![row],
markers: None,
};
serde_json::to_string(&grid).unwrap()
}
fn main() {
let mut arr = vec![1, 2, 3];
let mut _s = show_arr(&arr);
for _ in 0..5 {
arr.swap(0, 2); // break point
_s = show_arr(&arr);
}
dbg!(arr); // break point
println!("Hello, world!");
} It is more difficult for no-vm languages to debug with visualization. I think it's impossible to visualize without intrusive code. |
You might be right. Injecting code into runtimes of scripting languages is very easy (you can just eval' a class declaration), into languages interpreting bytecode harder (you need to invoke the class loader) and compiled languages very hard. A year ago, I worked on a MiniJava compiler in Rust. So I still think that this extension might be very useful for compile time languages in some specific cases. Beginners shouldn't use rust to learn algorithms anyway. Thanks for that demo btw.! Maybe a crate would be awesome! |
Cheers! |
Can this awesome plugin support Rust?
Rust has std::fmt::Debug which may be helpful to the implementation.
The text was updated successfully, but these errors were encountered: