Init
install¶
yay -S rustup
rustup default stable
export RUSTUP_DIST_SERVER='https://mirrors.sjtug.sjtu.edu.cn/rust-static'
export RUSTUP_UPDATE_ROOT='https://mirrors.sjtug.sjtu.edu.cn/rust-static/rustup'
curl https://mirrors.ustc.edu.cn/rust-static/rustup/rustup-init.sh | sh
cargo:
#~/.cargo/config
[source.mirror]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index/"
[source.crates-io]
replace-with = "mirror"
其他问题查看这个
debug 输出¶
如果要使用println!("{}",a)
这类的语法,必须要实现std::format:Display
,debug 同理,但是使用#[derive(Debug)]
就可以输出 struct。
#[derive(Debug)]
struct rect {
w: u32,
h: u32,
}
fn main() {
let r1 = rect{w:12,h:21};
println!("{:?}", r1);
}
trait、bounds、生命周期¶
T,E都是泛型,同时也实现了Display和Clone trait
fn some_funtion<T,E>(t:T,e:E)->i32
where T:Display+Clone,
E:Clone+Debug
{
}
fn longest_whith<'a, T>(x: &'a str, y: &'a str, ann: T) -> &'a str
where
T: Display,
{
println!("Ahhhhhh!!{}", ann);
if x.len() > y.len() {
x
} else {
y
}
}
cargo¶
https://doc.rust-lang.org/cargo/guide/why-cargo-exists.html
unsafe¶
https://doc.rust-lang.org/nomicon/index.html
std¶
https://doc.rust-lang.org/std/
example¶
https://doc.rust-lang.org/rust-by-example/conversion/try_from_try_into.html
async¶
https://rust-lang.github.io/async-book/01_getting_started/02_why_async.html
cheats¶
常用的 crates¶
- Rayon
- Actix
本页面的全部内容在 CC BY-NC-SA 4.0 协议之条款下提供,附加条款亦可能应用。