新增模块
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
mod second;
|
||||||
|
use second::ClassName;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let object = ClassName::new(1024);
|
||||||
|
object.public_method();
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
pub struct ClassName {
|
||||||
|
field: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ClassName {
|
||||||
|
pub fn new(value: i32) -> ClassName {
|
||||||
|
ClassName {
|
||||||
|
field: value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn public_method(&self) {
|
||||||
|
println!("from public method");
|
||||||
|
self.private_method();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn private_method(&self) {
|
||||||
|
println!("from private method");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user