liveBook · Manning

Contract

As explained in Refactoring to Rust

An API is a defined interface through which software components expose operations and exchange data.

An API contract describes the operations and data exchange a component makes available, along with behavior callers can rely on. In Rust, public visibility determines which items crate users can call; a public re-export can provide a shorter path while hiding the module hierarchy. section 5.2.2 section 1.3

pub mod the {
  pub mod secret {
    pub mod entrance {
      pub mod to {
        pub mod the {
          pub mod forest {
            pub fn enter() { }
          }
        }
      }
    }
  }
}

pub use the::secret::entrance::to::the::forest::enter;

A public re-export gives users a short entry point to a function nested deep in the module tree. section 5.2.2

A contract also includes behavior that should remain consistent during refactoring. Small, independent changes, automated tests, and monitoring help check that behavior as changes are deployed. section 1.1

How Refactoring to Rust covers it

How deep it goes
Explains public visibility, re-exports, and behavior compatibility with examples, but gives no formal contract schema.
Examples
Uses a forest crate to contrast deep function paths with a short re-exported entry point.
What you can do after
Apply it by exposing intended entry points and checking that refactored code preserves existing behavior.
How it connects
Links API contracts with Rust visibility, re-exports, refactoring, and type-system guarantees for data exchange.

Also explained in

Compare how 45 books explain contract →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.