Skip to content

Commit

Permalink
chore: rust
Browse files Browse the repository at this point in the history
  • Loading branch information
shfshanyue committed Nov 27, 2022
1 parent 8d50eec commit 6fcdc09
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package-lock.gz
.DS_Store
jsonl
*.out
dist
dist
rust
2 changes: 1 addition & 1 deletion api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const routes: Record<string, RequestListener> = {
res.end(JSON.stringify({
cors: true
}))
}
},
}
export default function handler(req: IncomingMessage, res: ServerResponse) {
for (const [path, handle] of Object.entries(routes)) {
Expand Down
7 changes: 7 additions & 0 deletions rust/basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions rust/basic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "basic"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
2 changes: 2 additions & 0 deletions rust/basic/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
cargo watch -x run
14 changes: 14 additions & 0 deletions rust/basic/src/bin/owner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Fix the error without removing code line
fn main() {
let s = String::from("hello, world");

// print_str(s.clone());
print_str(s);

println!("{}", s);
}

// or use &String
fn print_str(s: String) {
println!("{}",s)
}
27 changes: 27 additions & 0 deletions rust/basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fn main() {
// 默认不可变变量
let x = 4;

// 打印只能通过字符串打印,与 python 一致
println!("{}", x);

// 函数加 ! 表示宏
println!("Hello, world!");

let mut y = 3;
println!("{}", y);
y = 10;
println!("{}", y);

owner();
}

fn owner () {
let a = 3;
let b = a;
println!("{}, {}", a, b);

let s1 = String::from("hello");
let s2 = s1.clone();
println!("{}, {}", s2, s2);
}

1 comment on commit 6fcdc09

@vercel
Copy link

@vercel vercel bot commented on 6fcdc09 Nov 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

node-examples – ./

node-examples-shanyue.vercel.app
node-examples.vercel.app
node-examples-git-master-shanyue.vercel.app

Please sign in to comment.