Complete the code to make the function accessible outside the module.
mod greetings {
pub fn [1]() {
println!("Hello!");
}
}
fn main() {
greetings::hello();
}The function name must match the call in main. Here, hello is the correct name.
Complete the code to make the struct field accessible outside the module.
mod person {
pub struct Person {
pub [1]: String,
age: u32,
}
}
fn main() {
let p = person::Person { name: String::from("Alice"), age: 30 };
println!("Name: {}", p.name);
}The field name must be public to be accessed outside the module.
Fix the error by completing the code to allow access to the function from outside the module.
mod utils {
[1]() {
println!("Utility function");
}
}
fn main() {
utils::helper();
}pub keyword.pub but missing fn keyword.The function must be declared as pub fn helper to be accessible outside the module.
Fill both blanks to make the module and its function accessible from outside.
mod [1] { pub fn [2]() { println!("Inside module"); } } fn main() { [1]::[2](); }
The module is named utils and the function run is called in main.
Fill all three blanks to create a public struct with a public method accessible outside the module.
mod shapes {
pub struct [1] {
pub size: u32,
}
impl [1] {
pub fn [2](&self) -> u32 {
self.size
}
}
}
fn main() {
let s = shapes::[1] { size: 10 };
println!("Size: {}", s.[2]());
}The struct is named Square and the method get_size returns the size.