Modules Flashcards

1
Q

What is crate

A

Crate is a compilation unit in rust; Crate is compiled to binary ro library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is cargo

A

The official Rust package management tool for crates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a module

A

Logically groups code within a crate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is crate.io

A

The official Rust package registry.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Syntax of a module

A

//public module
pub mod a_public_module{
pub fn a_public_function(){

}    fn a_private_function() {
  //private function    } }

// private module
mod a_private_module {
fn a_private_function() {
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Example defining a module

A

pub mod movies {
pub fn play(name:String) {
println!(“Playing movie {}”,name);
}
}
fn main(){
movies::play(“Herold and Kumar”.to_string());
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to import a module

A

pub mod movies{
pub fn play(name:String) {
println!(“Playing movie {}”,name);
}
}

use movies::play;
fn main(){
play(“YOU”.to_string());
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to do nested modules

A

pub mod movies {
pub mod english {
pub mod comedy {
pub fn play(name:String) {
println!(“Playing comedy movie {}”,name);
}
}
}
}
use movies::english::comedy::play;
// importing a public module

fn main() {
// short path syntax
play(“Herold and Kumar”.to_string());
play(“The Hangover”.to_string());

//full path syntax
movies::english::comedy::play(“Airplane!”.to_string());
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly