The source code to import a module using the "use" keyword is given below. The given program is compiled and executed successfully.
// Rust program to import a module
// using the "use" keyword
pub mod Sample {
pub fn sayHello(name:String) {
println!("Hello {}",name);
}
}
use Sample::sayHello;
fn main(){
sayHello("Herry Potter".to_string());
}
Output:
Hello Herry Potter
Explanation:
In the above program, we created a module Sample. The Sample module contains a function sayHello() to print the message. And, we imported the sayHello() function of module Sample using the below statement.
use Sample::sayHello;
In the main() function, we called the sayHello() method with a specified string and printed the result.
Program/Source Code:
The source code to import a module using the "use" keyword is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a module Sample. The Sample module contains a function sayHello() to print the message. And, we imported the sayHello() function of module Sample using the below statement.
In the main() function, we called the sayHello() method with a specified string and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer