Create public APIs in Rust by marking modules and items with pub while keeping internal helpers private, then re-export only the necessary symbols at the crate root.
// src/lib.rs
pub mod kinds;
pub mod utils;
pub use kinds::PrimaryColor;
pub use utils::mix;
// src/kinds.rs
pub enum PrimaryColor {
Red,
Yellow,
Blue,
}
// src/kinds.rs (continued)
pub enum SecondaryColor {
Orange,
Green,
Purple,
}
// src/utils.rs
use crate::kinds::*;
pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
SecondaryColor::Orange
}
This structure exposes PrimaryColor and mix to users while hiding internal details like SecondaryColor unless explicitly re-exported.