Skip to content

Instantly share code, notes, and snippets.

@nexssp
Created July 20, 2020 14:25
Show Gist options
  • Save nexssp/86026a04753aec3609eec3fcdeb934e8 to your computer and use it in GitHub Desktop.
Save nexssp/86026a04753aec3609eec3fcdeb934e8 to your computer and use it in GitHub Desktop.
Nexss Programmer Hello World Template
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! serde = "*"
//! serde_derive = "*"
//! serde_json = "*"
//! rustc_version = "*"
//! ```
// Reads JSON data from stdin, adds "HelloFromRust":"version number" to JSON, write to stdout JSON string
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
extern crate rustc_version;
use rustc_version::{version};
use std::io::{self, Write};
// use std::mem;
fn main() -> io::Result<()> {
let mut nexss_stdout = String::new();
match io::stdin().read_line(&mut nexss_stdout) {
Ok(_) => {
// println!("{} bytes read", n);
let mut nexss_stdout:serde_json::Value = serde_json::from_str(&nexss_stdout).unwrap();
nexss_stdout["HelloFromRust"] = serde_json::Value::String(version().unwrap().to_string());
io::stdout().write_all(nexss_stdout.to_string().as_bytes())?;
}
Err(error) => println!("error: {}", error),
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment