Skip to content

Commit 269d305

Browse files
author
Brian Obot
committed
Updates
1 parent 9800751 commit 269d305

9 files changed

+40
-1
lines changed

14e_use_library

414 KB
Binary file not shown.

lib14b_modules_extended.rlib

8.73 KB
Binary file not shown.

lib14d_crate_in_rust.rlib

5.98 KB
Binary file not shown.

lib14e_use_library.rlib

5.13 KB
Binary file not shown.

src/bin/14c_modules_struct_fields.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ fn main() {
4444
println!("Person last name: {}", person.last_name);
4545

4646
// self can be used to refer to the current module
47-
// super can be used to refer to the parent module
47+
// super can be used to refer to the parent scope
4848
let greeting = person.greet();
4949
println!("Greeting: {}", greeting);
5050

51+
println!("Current Module: {:?}", module_path!());
52+
5153
}

src/bin/14d_crate_in_rust.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// crate is a compilation unit in Rust Programming Language
2+
// modules do not get compiled individually, only crates do
3+
4+
// a crate can be compiled into a binary or a library
5+
// by default crate are compiled into binary
6+
7+
// a crate can be compiled as library with
8+
// rustc --crate-type=lib <file_name>.rs
9+
10+
// the name of the compiled library is derived from adding lib infront of the filename
11+
// but this can customized with the --crate-name flag
12+
13+
pub fn public_function() -> u8 {
14+
12
15+
}
16+
17+
fn _private_function() -> u8 {
18+
13
19+
}

src/bin/14e_use_library.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let result: u8 = rary::public_function();
3+
println!("Result = {}", result);
4+
}

src/bin/14f_cargo.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// this is rust official package management tool
2+
// it can integrate with crate.io (official rust registry for public crates)
3+
// awareness of unittests
4+
// awareness of benchmarks
5+
6+
// when using Cargo, cargo build can be used from any part of the project, including subdirectories
7+
8+
// NOTE: when using cargo to run test, it may run some test concurrently, so ensure the test do not race
9+
// in cases where a simple compilation bu cargo is not enough to build a project,
10+
// the steps needed to build the projec can be specified in a build attribute of the package section
11+
// of the cargo.Toml file, or it can be specified in a file called build.rs.
12+
13+
// the build script is a rust file that would be compiled invoked prior to the compilation of anything else in the package
14+

tests/test_intro.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)