Pybites Logo Rust Platform

Re-exports and API Design

Medium +3 pts

🎯 In Python, a well-designed library lets users import from the top level:

from mylib import User, Config, AppError

Even though internally User might live in mylib.internal.models.user. You achieve this by importing into __init__.py:

# mylib/__init__.py
from .internal.models.user import User
from .internal.config import Config
from .internal.errors import AppError

Rust uses the same pattern with pub use. You organize code internally however makes sense, then create a clean public API with re-exports. The internal structure is hidden — users never see it.

The prelude pattern

Many Rust libraries provide a prelude module — a …

Login to see the full exercise.