new programm for password generation
This commit is contained in:
parent
5a945cdcb0
commit
d9f48e9fcc
9 changed files with 528 additions and 40 deletions
35
enum.rs
Executable file
35
enum.rs
Executable file
|
@ -0,0 +1,35 @@
|
|||
// enum
|
||||
//
|
||||
|
||||
|
||||
// main function
|
||||
fn main() {
|
||||
// use enums
|
||||
let x: Message = Message::Move { x: 3, y: 4 };
|
||||
let y: BoardGameTurn = BoardGameTurn::Move { squares: 1 };
|
||||
|
||||
// enum working like function
|
||||
let m = Message::Write("Hello World".to_string());
|
||||
let x = foo("Hello World".to_string()); // same as above, using function 'foo()'
|
||||
|
||||
// convert vector of strings into vector of Message::Write
|
||||
let v = vec!["Hello".to_string(), "World".to_string()];
|
||||
let v1: Vec<Message> = v.into_iter().map(Message::Write).collect();
|
||||
}
|
||||
|
||||
// enmus
|
||||
enum Message {
|
||||
Quit,
|
||||
ChangeColor(i32, i32, i32), // tulpe
|
||||
Move { x: i32, y: i32 }, // struct
|
||||
Write(String),
|
||||
}
|
||||
enum BoardGameTurn {
|
||||
Move { squares: i32 },
|
||||
Pass,
|
||||
}
|
||||
|
||||
//functions
|
||||
fn foo(x: String) -> Message {
|
||||
Message::Write(x)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue