From 1d023d0d97f0516a151c1c62d4b71846a3593aeb Mon Sep 17 00:00:00 2001 From: daleclack Date: Sat, 24 Dec 2022 13:23:17 +0800 Subject: [PATCH] Update Rust cfgfile --- Gtkmm4/gtk143_menutest2/src/MenuBar.hh | 2 +- Rust_tests/rust_cfgfile/src/main.rs | 32 ++- Rust_tests/rust_cfgfile/xe_config | 3 + Rust_tests/rust_file/Cargo.lock | 279 +++++++++++++++++++++- Rust_tests/rust_file/Cargo.toml | 2 +- Rust_tests/rust_file/src/main.rs | 2 +- Rust_tests/rust_file2/.vscode/launch.json | 47 ++++ Rust_tests/rust_file2/Cargo.lock | 7 + Rust_tests/rust_file2/Cargo.toml | 8 + Rust_tests/rust_file2/src/main.rs | 23 ++ 10 files changed, 393 insertions(+), 12 deletions(-) create mode 100644 Rust_tests/rust_cfgfile/xe_config create mode 100644 Rust_tests/rust_file2/.vscode/launch.json create mode 100644 Rust_tests/rust_file2/Cargo.lock create mode 100644 Rust_tests/rust_file2/Cargo.toml create mode 100644 Rust_tests/rust_file2/src/main.rs diff --git a/Gtkmm4/gtk143_menutest2/src/MenuBar.hh b/Gtkmm4/gtk143_menutest2/src/MenuBar.hh index 660077a..c4cc19b 100644 --- a/Gtkmm4/gtk143_menutest2/src/MenuBar.hh +++ b/Gtkmm4/gtk143_menutest2/src/MenuBar.hh @@ -21,4 +21,4 @@ private: // Menu Models Glib::RefPtr builder_def, builder_win1, builder_win2; Glib::RefPtr model_default, model_win1, model_win2; -}; \ No newline at end of file +}; diff --git a/Rust_tests/rust_cfgfile/src/main.rs b/Rust_tests/rust_cfgfile/src/main.rs index 1b31126..98cc2b5 100644 --- a/Rust_tests/rust_cfgfile/src/main.rs +++ b/Rust_tests/rust_cfgfile/src/main.rs @@ -1,5 +1,33 @@ -use std::fs; +use std::{fs, io, iter::Map}; fn main() { - println!("Hello, world!"); + // Read the filename + let mut filename = String::new(); + io::stdin() + .read_line(&mut filename) + .expect("Failed to read the line!"); + + // Open the file + let filename = filename.trim(); + let config_str = match fs::read_to_string(filename) { + Ok(config_str) => config_str, + Err(_) => String::from("-1"), + }; + + //println!("The content of file:{}", config_str); + + let v: Vec<&str> = config_str.splitn(3, '\n').collect(); + + //println!("{}\n{}\n{}\n", v[0], v[1], v[2]); + + let longterm: Vec<&str> = v[0].split("=").collect(); + let stable: Vec<&str> = v[1].split("=").collect(); + let devel: Vec<&str> = v[2].split("=").collect(); + + println!("{}:{}", longterm[0], longterm[1]); + println!("{}:{}", stable[0], stable[1]); + println!("{}:{}", devel[0], devel[1]); + + // Get a line of string + //let config_map : Map; } diff --git a/Rust_tests/rust_cfgfile/xe_config b/Rust_tests/rust_cfgfile/xe_config new file mode 100644 index 0000000..c6f1581 --- /dev/null +++ b/Rust_tests/rust_cfgfile/xe_config @@ -0,0 +1,3 @@ +Longterm=5.7 +Stable=7.12 +Develop=8.0 diff --git a/Rust_tests/rust_file/Cargo.lock b/Rust_tests/rust_file/Cargo.lock index 023389d..80da712 100644 --- a/Rust_tests/rust_file/Cargo.lock +++ b/Rust_tests/rust_file/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -9,23 +18,154 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "chrono" -version = "0.4.19" +name = "bumpalo" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" + +[[package]] +name = "cc" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ - "libc", + "iana-time-zone", + "js-sys", "num-integer", "num-traits", "time", + "wasm-bindgen", "winapi", ] [[package]] -name = "libc" -version = "0.2.117" +name = "codespan-reporting" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cxx" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "link-cplusplus" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +dependencies = [ + "cc", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] [[package]] name = "num-integer" @@ -46,6 +186,30 @@ dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "proc-macro2" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + [[package]] name = "rust_file" version = "0.1.0" @@ -53,6 +217,32 @@ dependencies = [ "chrono", ] +[[package]] +name = "scratch" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "time" version = "0.1.44" @@ -64,12 +254,78 @@ dependencies = [ "winapi", ] +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + [[package]] name = "winapi" version = "0.3.9" @@ -86,6 +342,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Rust_tests/rust_file/Cargo.toml b/Rust_tests/rust_file/Cargo.toml index c8b7769..daee1cb 100644 --- a/Rust_tests/rust_file/Cargo.toml +++ b/Rust_tests/rust_file/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -chrono = "0.4" +chrono = "0.4.23" diff --git a/Rust_tests/rust_file/src/main.rs b/Rust_tests/rust_file/src/main.rs index 2c6ff7e..7aeb0bc 100644 --- a/Rust_tests/rust_file/src/main.rs +++ b/Rust_tests/rust_file/src/main.rs @@ -8,7 +8,7 @@ fn main() { // Get current time let now = Utc::now(); let local = Local::now(); - let naive_time = NaiveDate::from_ymd(2017, 5, 19).and_hms(0, 0, 0); + let naive_time = NaiveDate::from_ymd_opt(2017, 5, 19).unwrap().and_hms_opt(0, 0, 0).unwrap(); let build_version = DateTime::::from_utc(naive_time, Utc); // Calculate the duration time diff --git a/Rust_tests/rust_file2/.vscode/launch.json b/Rust_tests/rust_file2/.vscode/launch.json new file mode 100644 index 0000000..2a5e90c --- /dev/null +++ b/Rust_tests/rust_file2/.vscode/launch.json @@ -0,0 +1,47 @@ +{ + // 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 executable 'rust_file2'", + "cargo": { + "args": [ + "build", + "--bin=rust_file2", + "--package=rust_file2", + "--release" + ], + "filter": { + "name": "rust_file2", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'rust_file2'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=rust_file2", + "--package=rust_file2", + "--release" + ], + "filter": { + "name": "rust_file2", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Rust_tests/rust_file2/Cargo.lock b/Rust_tests/rust_file2/Cargo.lock new file mode 100644 index 0000000..63fe54b --- /dev/null +++ b/Rust_tests/rust_file2/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rust_file2" +version = "0.1.0" diff --git a/Rust_tests/rust_file2/Cargo.toml b/Rust_tests/rust_file2/Cargo.toml new file mode 100644 index 0000000..1b76a3a --- /dev/null +++ b/Rust_tests/rust_file2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust_file2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/Rust_tests/rust_file2/src/main.rs b/Rust_tests/rust_file2/src/main.rs new file mode 100644 index 0000000..884c7da --- /dev/null +++ b/Rust_tests/rust_file2/src/main.rs @@ -0,0 +1,23 @@ +/* +Read Contents from a file, +if read failed, a error message will shown, +and the program should not panic +built in 2022/12/23, dale clack +*/ +use std::{fs, io}; + +fn main() { + let mut filename1 = String::new(); + + // Get file name to read + io::stdin().read_line(&mut filename1).expect("Can't read line"); + let filename = filename1.trim(); + + // Read content from file + let file_str = match fs::read_to_string(filename){ + Ok(file_str) => file_str, + Err(_) => String::from("default config"), + }; + + println!("The Content of file:\n{}", file_str); +}