其他分享
首页 > 其他分享> > rust实战入门到进阶(1)

rust实战入门到进阶(1)

作者:互联网

1、自适应安装
(1)在Unix/Linux下,使用curl https://sh.rustup.rs -sSf | sh在Shell中运行,它自动启动安装过程:首先,下载并运行rustup-init.sh,然后,依次下载并运行rustup-init适合当前平台的可执行文件的正确版本。

$ curl https://sh.rustup.rs -sSf | sh
...
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1
...
Rust is installed now. Great!

安装脚本在下次登录时自动加Rust到系统路径PATH 。
如果想马上开始使用Rust而不是重新启动你的终端,在shell中运行以下命令来手动添加Rust到你的系统路径:

$ source $HOME/.cargo/env

也可加入下面行到 ~/.bash_profile:

$ export PATH="$HOME/.cargo/bin:$PATH"

打开https://www.rust-lang.org/tools/install安装
更新与卸载
$ rustup update
$ rustup self uninstall
(2)在Windows下,下载并运行rustup-init.exe,将自动安装正确版本。下载地址如下:
https://www.rust-lang.org/zh-CN/tools/install
2、独立安装,下载地址如下:
https://forge.rust-lang.org/infra/other-installation-methods.html#standalone
下载后执行安装文件即可。

//rust-2
fn get_distance(x1:f64,y1:f64,x2:f64,y2:f64)->f64{
	let dis=((x1-x2).powi(2)+(y1-y2).powi(2)).sqrt();
    dis
}
fn main() {
    println!("{}",get_distance(11.5,16.8,29.3,10.9));
}

单元测试
//rust-3
fn get_distance(x1:f64,y1:f64,x2:f64,y2:f64)->f64{
	let dis=((x1-x2).powi(2)+(y1-y2).powi(2)).sqrt();
    dis
}
#[test]
fn test_get_distance(){
	let x:f64=(1.-10.)*(1.-10.)+(2.-20.)*(2.-20.);
	assert_eq!(get_distance(1.,2.,10.,20.),x.sqrt());
}
fn main() {
    println!("{}",get_distance(11.5,16.8,29.3,10.9));
}
# cargo test
   Compiling learnrust3 v0.1.0 (F:\pro\learnrust\learnrust3)
    Finished test [unoptimized + debuginfo] target(s) in 2.20s
     Running unittests (target\debug\deps\learnrust3-4f3a444115c274cb.exe)

running 1 test
test test_get_distance ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Redox是一个用Rust语言编写的类UNIX操作系统 , 它的目标是把Rust语言的创新带入到一个现代的微内核和全系列的应用程序。

https://www.redox-os.org/zh/docs/
Rust语言实现
微内核设计
包括可选的GUI程序 - Orbital
支持Rust标准库
MIT授权
驱动运行在用户空间
包括常见的Unix命令
C程序的新移植库
Redox source:
https://gitlab.redox-os.org/redox-os/redox

Redox是一个用pure Rust编写的通用操作系统。我们的目标是提供一个功能完整的类unix微内核,既安全又免费。
我们与POSIX有适度的兼容性,允许Redox在无需移植的情况下运行许多程序。

标签:进阶,get,rustup,rust,https,test,f64,Rust,入门
来源: https://blog.csdn.net/AI_LX/article/details/117129737