crate-module/use-pub #276
Replies: 7 comments 4 replies
-
fn main() {
assert_eq!(front_of_house::hosting::seat_at_table(), "sit down please");
assert_eq!(hello_package::eat_at_restaurant(),"yummy yummy!");
}```
hello_package::eat_at_restaurant() 为什么可以?这个包不是叫 hello-package 吗? |
Beta Was this translation helpful? Give feedback.
1 reply
-
1、 use std::fmt::Result;
use std::io::Result as ioResult;
fn main() {} 2、第一种 use std::collections::{HashMap,BTreeMap,HashSet};
fn main() {
let _c1:HashMap<&str, i32> = HashMap::new();
let mut c2 = BTreeMap::new();
c2.insert(1, "a");
let _c3: HashSet<i32> = HashSet::new();
} 第二种,展开 use std::collections::HashMap;use std::collections::BTreeMap;use std::collections::HashSet;
fn main() {
let _c1:HashMap<&str, i32> = HashMap::new();
let mut c2 = BTreeMap::new();
c2.insert(1, "a");
let _c3: HashSet<i32> = HashSet::new();
} 3、略 |
Beta Was this translation helpful? Give feedback.
1 reply
-
第3题不是这样的吗? mod hello_package {
pub mod hosting {
pub fn seat_at_table() -> &'static str {
"sit down please"
}
}
pub fn eat_at_restaurant() -> &'static str {
"yummy yummy!"
}
}
fn main() {
assert_eq!(hello_package::hosting::seat_at_table(), "sit down please");
assert_eq!(hello_package::eat_at_restaurant(),"yummy yummy!");
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
crate-module/use-pub
Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects.
https://zh.practice.rs/crate-module/use-pub.html
Beta Was this translation helpful? Give feedback.
All reactions