#华氏度 #摄氏度 #尺度 #温度 #转换 # #用户输入

temp_convertor

A rust library crate that will convert any temperature value given by the user from Celsius to Fahrenheit scale or from Fahrenheit to Celsius scale

1个不稳定版本

0.1.0 2020年5月10日

#6 in #华氏度

MIT/Apache

7KB

温度转换器

A rust library crate that will convert any temperature value given by the user from Celsius to Fahrenheit scale or from Fahrenheit to Celsius scale.

用法

To use this library in your code, you just need to add following line in the dependencies section of your cargo.toml file.

[dependencies]
temp_convertor = "0.1.0"

Your cargo.toml file will look like this

[package]
name = "temp_convertor"
version = "0.1.0"
authors = ["Haseeb ul Hassan <[email protected]>"]
edition = "2018"

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

[dependencies]
temp_convertor = "0.1.0"

Now, just come in src/main.rs to use this library crate. Write the following lines to get the conversion of temperature from Celsius to Fahrenheit. For example,the temperature entered by the user is 96.8°.

use temp_convertor;
fn main () {
   temp_convertor::convertor::celsius_to_fahrenheit(96.8);  
}

Another way of using this crate

use temp_convertor::convertor;
fn main () {
   convertor::fahrenheit_to_celsius(96.8);  
}

Now in the end, just use cargo run to get the desired conversion of temperature.

语法

Here, the temp_convertor is the name of crate, convertoris the module and celsius_to_fahrenheit(96.8) and fahrenheit_to_celsius(96.8) are the functions that are converting the temperature from Celsius to Fahrenheit and from Fahrenheit to Celsius as well. Both are taking 96.8 as an argument.

注意

You can pass only floating point numbers as argument in the these function celsius_to_fahrenheit(96.8) and fahrenheit_to_celsius(96.8).

输出

The output will be like this

You entered: 96.8°
The temperature in Fahrenheit is: 206.24°
You entered: 96.8°
The temperature in Celsius is: 36.00°

No runtime deps