7 Rustのモジュールシステム #7
Replies: 8 comments 12 replies
-
|
Beta Was this translation helpful? Give feedback.
-
クレート
例) |
Beta Was this translation helpful? Give feedback.
-
モジュール
mod front_of_house {
mod hosting {
fn add_to_waitlist() {}
fn seat_at_table() {}
}
mod serving {
fn take_order() {}
fn serve_order() {}
fn take_payment() {}
}
}
|
Beta Was this translation helpful? Give feedback.
-
モジュールシステムのプライバシー
|
Beta Was this translation helpful? Give feedback.
-
use
mod front_of_house {
pub mod hosting {
pub fn add_to_waitlist() {}
}
}
use self::front_of_house::hosting;
pub fn eat_at_restaurant() {
hosting::add_to_waitlist();
hosting::add_to_waitlist();
hosting::add_to_waitlist();
}
use std::collections::HashMap;
fn main() {
let mut map = HashMap::new();
map.insert(1, 2);
}
|
Beta Was this translation helpful? Give feedback.
-
pub use による 再公開 (re-expoting)
mod front_of_house {
pub mod hosting {
pub fn add_to_waitlist() {}
}
}
pub use crate::front_of_house::hosting;
pub fn eat_at_restaurant() {
hosting::add_to_waitlist();
hosting::add_to_waitlist();
hosting::add_to_waitlist();
} |
Beta Was this translation helpful? Give feedback.
-
ネストしたパスをまとめてuse する
パスに同じprefixを持つ場合 // before
use std::cmp::Ordering;
use std::io;
// after
use std::{cmp::Ordering, io}; 片方がもう一つのサブパスであるような場合 // before
use std::io;
use std::io::Write;
// after
use std::io::{self, Write}; |
Beta Was this translation helpful? Give feedback.
-
モジュールのファイル分割
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://doc.rust-jp.rs/book-ja/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html
Beta Was this translation helpful? Give feedback.
All reactions