Add rust env test
This commit is contained in:
parent
597b2eb6ae
commit
650d378921
17
README.md
17
README.md
|
@ -38,7 +38,7 @@ Win32 exe supports WinXP and above
|
|||
|
||||
The Sample Code to get current dir
|
||||
|
||||
```C
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -80,7 +80,20 @@ public class Args{
|
|||
Rust Version
|
||||
|
||||
```rust
|
||||
fn main(){
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
// Get executive path
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let execpath: String = args[0].clone();
|
||||
|
||||
// Handle the path string
|
||||
let exec_len: usize = 13;
|
||||
let length: usize = execpath.len() - exec_len;
|
||||
let path: &str = &execpath[0..length];
|
||||
|
||||
// Print the path of executive
|
||||
println!("{}", path);
|
||||
}
|
||||
|
||||
```
|
||||
|
|
|
@ -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_env_test'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"build",
|
||||
"--bin=rust_env_test",
|
||||
"--package=rust_env_test",
|
||||
"--release"
|
||||
],
|
||||
"filter": {
|
||||
"name": "rust_env_test",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug unit tests in executable 'rust_env_test'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--bin=rust_env_test",
|
||||
"--package=rust_env_test",
|
||||
"--release"
|
||||
],
|
||||
"filter": {
|
||||
"name": "rust_env_test",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust_env_test"
|
||||
version = "0.1.0"
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "rust_env_test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -0,0 +1,15 @@
|
|||
use std::env;
|
||||
|
||||
fn main() {
|
||||
// Get executive path
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let execpath: String = args[0].clone();
|
||||
|
||||
// Handle the path string
|
||||
let exec_len: usize = 13;
|
||||
let length: usize = execpath.len() - exec_len;
|
||||
let path: &str = &execpath[0..length];
|
||||
|
||||
// Print the path of executive
|
||||
println!("{}", path);
|
||||
}
|
Loading…
Reference in New Issue