belongs to collection: Rust Modules Programs
In this program, we will create a module that contains a function. A module is a group of similar types of functions.
Program/Source Code:
The source code to create a simple module is given below. The given program is compiled and executed successfully.
// Rust program to create a simple module pub mod Sample { pub fn sayHello(name:String) { println!("Hello {}",name); } } fn main(){ Sample::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.
In the main() function, we called the sayHello() method with a specified string and printed the result.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to create a simple module 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.
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