Skip to content

Flatten pub-use-star re-exports into explicit public API #76

Open

Description

@darinkishore

Problem

Every mod.rs does pub use foo::* and lib.rs re-exports everything:

pub use adapter::chat::*;
pub use augmentation::*;
pub use core::*;
pub use data::*;
// ... etc

This makes the entire crate flat at the root — hundreds of items. Consequences:

  • Name collisions (e.g. Prediction vs Predicted, DSRs ToolCall vs rig ToolCall)
  • Impossible to tell what's public API vs internal
  • IDE autocomplete noise
  • Adding anything to any submodule automatically becomes public

Proposal

Move to explicit re-exports at the crate root:

// Core types users need
pub use core::{Module, Signature, Predict, Predicted, CallMetadata, PredictError, LM};
pub use core::signature::SignatureSchema;
// ... etc

Keep pub mod for submodules so users can reach internals via dspy_rs::core::whatever if needed, but the root namespace should be curated.

Impact

  • Breaking change for downstream code that relies on flat imports
  • But the crate is pre-1.0, so this is the time to do it

Activity

  1. darinkishore commented on Feb 12, 2026

    @darinkishore
    CollaboratorAuthor

    Codebase audit — current re-export surface

    lib.rs lines 100-112:

    pub use adapter::chat::*;
    pub use augmentation::*;
    pub use core::*;
    pub use data::dataloader::*;
    pub use data::prediction::*;
    pub use data::serialize::*;
    pub use data::utils::*;
    pub use evaluate::*;
    pub use modules::*;
    pub use optimizer::*;
    pub use predictors::*;
    pub use utils::*;

    Plus each mod.rs does its own pub use *:

    • core/mod.rs → pub use lm::*; pub use module::*; pub use specials::*; pub use settings::*; etc.
    • data/mod.rs → pub use dataloader::*; pub use example::*; pub use prediction::*; etc.

    This creates a flat namespace at crate root with name collisions already present (DSRs ToolCall vs rig ToolCall).

    Proposed curated root exports:

    // Types every user needs
    pub use core::signature::Signature;
    pub use core::module::Module;
    pub use core::schema::SignatureSchema;
    pub use core::predicted::{Predicted, CallMetadata};
    pub use core::errors::{PredictError, ParseError, LmError};
    pub use core::lm::LM;
    pub use core::settings::configure;
    pub use predictors::predict::Predict;
    pub use predictors::example::Example;
    pub use modules::chain_of_thought::ChainOfThought;
    pub use augmentation::WithReasoning;
    pub use evaluate::{TypedMetric, evaluate_trainset};
    pub use optimizer::{Optimizer, COPRO, GEPA, MIPROv2};
    pub use data::dataloader::DataLoader;
    
    // Keep pub mod for everything so users CAN reach internals
    pub mod adapter;
    pub mod core;
    // ...

    Breaking change scope: Any downstream code using use dspy_rs::* that relied on internal types being at root level. But the crate is pre-1.0 and the downstream user count is small. Better to do this now.

    Approach: do it in one PR. cargo check against all tests/examples will catch everything that breaks. Most fixes will be adding a module path prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions