en/src/crate-module/use-pub.md
as keyword.use std::fmt::Result;
use std::io::Result;
fn main() {}
// FILL in the blank in two ways
// DON'T add new code line
use std::collections::__;
fn main() {
let _c1:HashMap<&str, i32> = HashMap::new();
let mut c2 = BTreeMap::new();
c2.insert(1, "a");
let _c3: HashSet<i32> = HashSet::new();
}
pub usehello-package, add something to make the below code workfn main() {
assert_eq!(hello_package::hosting::seat_at_table(), "sit down please");
assert_eq!(hello_package::eat_at_restaurant(),"yummy yummy!");
}
Sometimes we want an item only be public to a certain crate. For this we can use the pub(in Crate) syntax.
pub mod a {
pub const I: i32 = 3;
fn semisecret(x: i32) -> i32 {
use self::b::c::J;
x + J
}
pub fn bar(z: i32) -> i32 {
semisecret(I) * z
}
pub fn foo(y: i32) -> i32 {
semisecret(I) + y
}
mod b {
pub(in crate::a) mod c {
pub(in crate::a) const J: i32 = 4;
}
}
}
The full code of hello-package is here.
You can find the solutions here (under the solutions path), but only use it when you need it :)