Add rust env test

This commit is contained in:
daleclack 2022-02-13 21:48:14 +08:00
parent 597b2eb6ae
commit 650d378921
5 changed files with 92 additions and 2 deletions

View File

@ -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);
}
```

View File

@ -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}"
}
]
}

7
rust_tests/rust_env_test/Cargo.lock generated Normal file
View File

@ -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"

View File

@ -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]

View File

@ -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);
}