RUST-Basic
Variable
Data Type
String
Vec
1 | Vec::join |
Values
Option
Statement
Symbol
1 | {:?} |
Loop Statement
Condition Statement
Function Feature
#[derive(Debug)]
#[derive(Debug)] is an attribute in Rust used to automatically generate code that implements the Debug trait. The Debug trait is a built-in trait in Rust that provides a default way to format and print values for debugging purposes.
By adding #[derive(Debug)] to a struct or an enum, the Rust compiler automatically generates the necessary code to implement the Debug trait. This allows us to use println! macro or other debugging tools to print and inspect the contents of the types.
#[test]
Function
.unwrap()
The .unwrap() method in Rust is used to extract the value from an Option or Result type. It returns the inner value if it exists or panics if it encounters a None or Err variant.
std::env::args()
std::env::args() is a function provided by the Rust standard library (std::env module) that returns an iterator over the command-line arguments passed to the program.
The args() function returns an iterator of type std::env::Args, which represents the individual command-line arguments as strings. The first element of the iterator (std::env::Args) is always the name of the executable binary itself.
Here’s an example of how to use std::env::args():
1 | use std::env; |
The output:
1 | $ ./my_program arg1 arg2 arg3 |
clap
1 | matches.values_of("text").unwrap(); |
- Example: use clap=“3”
1 | use clap::{App,Arg}; |