Today I learned about the glob operator, creating a library crate, and multiple binary crates
The Glob Operator:
The glob operator (*) lets you import everything from a module at once.
At first, it felt strong. Almost too powerful.
Up until now, Rust has been teaching me to be explicit, to name exactly what I'm bringing into scope. The glob operator relaxes that slightly.
That contrast made me think. Rust gives you convenience, but it also gives you responsibility.
Even as a learner, I can see how using a glob import might make code shorter but potentially less clear. It made me more aware of how imports shape readability.
Creating a Library Crate:
Learning how to create a library crate changed how I view Rust projects.
Before this, everything I built felt like "a program." Now I see that Rust encourages you to build reusable logic, code meant to be consumed by other parts of the project or even other projects.
A library crate feels like saying: this code is meant to be depended on.
That shift in perspective, from writing code for execution to writing code for reuse, feels like a major step in maturity.
Multiple Binary Crates:
This one surprised me. A single project can have multiple binary crates, meaning multiple entry points.
That made me realize Rust doesn't assume your project is a single purpose tool. You can structure a project to serve different commands, roles, or execution flows while sharing the same core logic.
It made everything I've learned about modules and visibility suddenly make more sense. Structure supports scale.
Some languages can have multiple main packages in a project, but they need to be in separate directories. Rust's approach with multiple binaries in the same workspace feels similar but more integrated.
At this point, I'm starting to see Rust in layers.
Ownership taught me about memory discipline. Enums taught me about modeling uncertainty. Modules taught me about structure. Visibility taught me about boundaries.
Crates and binaries are teaching me about architecture.
Rust doesn't just teach me how to code. It teaches me how to design systems.
I'm still learning and still early, I will get a clearer picture soon.
When you're building projects, do you start thinking about reusability and architecture upfront, or do you refactor toward it once things get complex?
// Using the glob operator (imports everything)
use std::collections::*;
fn example_glob() {
let mut map = HashMap::new();
map.insert("key", "value");
}
// Library crate structure
// src/lib.rs
pub fn greet(name: &str) -> String {
format!("Hello, {}", name)
}
pub fn farewell(name: &str) -> String {
format!("Goodbye, {}", name)
}
// Binary crate that uses the library
// src/main.rs
use my_library::greet;
fn main() {
println!("{}", greet("Rust"));
}
// Additional binary crate
// src/bin/other_tool.rs
fn main() {
println!("This is a separate binary in the same project");
}
// Documentation comment with examples
/// Adds two numbers together.
///
/// # Examples
///
/// ```
/// let sum = my_library::add(2, 3);
/// assert_eq!(sum, 5);
///
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
#Rust #RustLang #LearningRust #Programming #SoftwareEngineering #SoftwareArchitecture #CodeOrganization #LibraryDesign #Documentation #Blockchain #Solidity #SystemsDesign #CleanCode
Top comments (0)