rust-module-organization-public-api-design

Organize Rust modules and design stable public APIs with re-exports.

836|66|Updated Feb 3, 2025
One-click install
npx skills add https://github.com/kreuzberg-dev/html-to-markdown --skill rust-module-organization-public-api-design-kreuzberg-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-module-organization-public-api-design
Source: https://github.com/kreuzberg-dev/html-to-markdown/tree/main/.codex/skills/rust-module-organization-public-api-design
Command: npx skills add https://github.com/kreuzberg-dev/html-to-markdown --skill rust-module-organization-public-api-design-kreuzberg-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the challenge of organizing Rust code into logical modules and designing a stable, maintainable public API, preventing breaking changes and improving code discoverability.

Core Features & Use Cases

  • Module Structure: Provides principles for organizing code by feature and managing visibility (pub, pub(crate)).
  • Public API Definition: Guides on using src/lib.rs for re-exports to define a clear and stable interface.
  • Use Case: A Rust library maintainer can use this Skill to refactor their codebase, ensuring that future updates do not break existing user code by carefully managing what is exposed publicly.

Quick Start

Use the rust-module-organization-public-api-design skill to learn how to define a stable public API for a Rust crate by organizing its modules and using re-exports effectively.

Frequently Asked Questions about rust-module-organization-public-api-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I organize Rust modules to define a stable public API?

Define your Rust public API by using `src/lib.rs` for re-exports to establish a clear interface. Organize modules by feature and manage visibility carefully with `pub` and `pub(crate)` to ensure backward compatibility and prevent unintended breaking changes.

What is the best way to prevent breaking changes in a Rust library?

Prevent breaking changes in a Rust library by carefully managing what is exposed publicly. Use `pub(crate)` to hide internal implementation details and validate your stable interface using tools like `cargo-public-api` to ensure future updates do not break existing user code.

How do I use re-exports in `src/lib.rs` for Rust module organization?

Use `src/lib.rs` to re-export items from nested modules, creating a flat and accessible public API surface. This pattern simplifies the user experience by hiding the internal module hierarchy while maintaining a stable, maintainable interface for your Rust library.

Does Rust support validating public API surfaces with `cargo-public-api`?

Yes, you can validate your Rust public API surface using `cargo-public-api`. This tool helps verify that your module organization and visibility controls correctly define the intended interface, ensuring maintainability and preventing unexpected breaking changes across versions.

When should I use `pub(crate)` visibility in Rust module organization?

Use `pub(crate)` visibility in Rust module organization when you need items to be accessible within your crate but hidden from external users. This prevents internal implementation details from leaking into your public API, ensuring stability and maintaining backward compatibility.