From 8207c28b6d0eed735858eb07c42906b62cdd64a5 Mon Sep 17 00:00:00 2001 From: wuaoxiang Date: Mon, 12 Oct 2020 11:00:53 +0800 Subject: [PATCH] Add fetch git last commit info example --- examples/basic_execute_shell_command.rs | 27 ++++++++++++++++--------- examples/double_linked_list.rs | 4 ++-- examples/gzip.rs | 2 -- examples/rust_decimal_lib_test.rs | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/basic_execute_shell_command.rs b/examples/basic_execute_shell_command.rs index ede79e4..5c1d275 100644 --- a/examples/basic_execute_shell_command.rs +++ b/examples/basic_execute_shell_command.rs @@ -1,12 +1,19 @@ -use std::process::Command; +#[derive(serde::Deserialize, Debug)] +struct CommitInfo { + hash: String, + date: String, + message: String +} -fn main() { - let mut cmd = Command::new("df"); - cmd.arg("-h"); - match cmd.output() { - Ok(output) => unsafe { - println!("{}", String::from_utf8_unchecked(output.stdout)); - }, - Err(e) => println!("{}", e), - } +fn main() -> Result<(), Box> { + let cmd_res = std::process::Command::new("git") + .arg("log") + .arg("-1") + .arg("--pretty=format:hash=\"%h\"\ndate=\"%ad\"\nmessage=\"%s\"") + .env("DATABASE_URL", "null") + .output()?; + let last_commit_str = String::from_utf8(cmd_res.stdout)?; + let last_commit: CommitInfo = toml::de::from_str(&last_commit_str)?; + dbg!(last_commit); + Ok(()) } diff --git a/examples/double_linked_list.rs b/examples/double_linked_list.rs index 46d8cf9..0ca7019 100644 --- a/examples/double_linked_list.rs +++ b/examples/double_linked_list.rs @@ -23,7 +23,7 @@ struct List { tail: Node, } -// impl List { +// impl List { // fn new(dummy_val: T) -> Self { // let mut head = Node::new(dummy_val); // let mut tail = Node::new(dummy_val); @@ -37,5 +37,5 @@ struct List { // } fn main() { - let mut head: Node = Node::new(-1); + let _head: Node = Node::new(-1); } diff --git a/examples/gzip.rs b/examples/gzip.rs index 7a6fbd7..ca8c6a0 100644 --- a/examples/gzip.rs +++ b/examples/gzip.rs @@ -22,6 +22,4 @@ fn main() { let decode_str = decode_gzip_bytes_to_str(gzip_bytes); println!("{}", decode_str); assert_eq!(decode_str.as_str(), s); - - use std::collections::BinaryHeap; } diff --git a/examples/rust_decimal_lib_test.rs b/examples/rust_decimal_lib_test.rs index edc97e2..e919312 100644 --- a/examples/rust_decimal_lib_test.rs +++ b/examples/rust_decimal_lib_test.rs @@ -1,7 +1,7 @@ use bigdecimal::BigDecimal; use rust_decimal::Decimal; // use rust_decimal::prelude::FromStr; -use rust_decimal::prelude::ToPrimitive; + use std::mem::size_of_val; use std::str::FromStr;