Add rust test code

This commit is contained in:
daleclack 2021-12-01 16:07:28 +08:00
parent fffe3bfaa8
commit 16d851d32d
8 changed files with 85 additions and 1 deletions

View File

@ -18,7 +18,7 @@ The file name is above:
public\_res\<filename\>\_\<file extension\> or public\_res\<filename\>\_\<file extension\>
~~Please compile with g++ or gcc (Clang is also supported)
Please compile with g++ or gcc (Clang is also supported)
(Visual Studio may have issues)
@ -33,3 +33,50 @@ before gtk17 supports Gtk3.6.4
gtk17 and above removed support for gtk3.18 and below
Win32 exe supports WinXP and above
The Sample Code to get current dir
```C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char ** argv){
//argv[0] for full application running path
const char * src = *argv;
//Get Size and store the content
int len = strlen(src);
char * tmp = malloc(len);
//The Name of application is "args.exe" for windows
//And named "args" for linux
#ifdef _WIN32
strncpy(tmp,src,len-8);
tmp[len-8]='\0';
#else
strncpy(tmp,src,len-4);
tmp[len-4]='\0';
#endif
printf("%s\n",tmp);
free(tmp);
return 0;
}
```
Java version
```java
public class Args{
public static void main(String[] args){
System.out.println(System.getProperty("user.dir"));
}
}
```
Rust Version
```rust
fn main(){
}
```

7
rust_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_test2"
version = "0.1.0"

8
rust_test/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "rust_test2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

5
rust_test/README.md Normal file
View File

@ -0,0 +1,5 @@
# The Rust test codes
The Sources files are in the "src" directory, and contain many tests
#### Note: each rust source file has it own main function, and it is not a normal project, please compile individual source file, don't try to run "cargo build" or "cargo run"

7
rust_test/src/main.rs Normal file
View File

@ -0,0 +1,7 @@
mod test;
mod test2;
mod test3;
fn main() {
println!("Hello, world!");
}

10
rust_test/src/test3.rs Normal file
View File

@ -0,0 +1,10 @@
//Get Current directory(May cause error when handling directory name with chinese)
fn main(){
let mut args = std::env::args();
let path = args.nth(0).unwrap();
let length = path.len();
println!("{}",path);
let path1 = &path[0..length-5];
println!("{}",path1);
}