新增模块

This commit is contained in:
林觅
2026-10-09 22:32:14 +08:00
parent 945e82e7ef
commit 78be51f432
2 changed files with 26 additions and 1 deletions
+6 -1
View File
@@ -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!");
} }
+20
View File
@@ -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");
}
}