liveBook · Manning

Library

As explained in Idiomatic Rust

A library is a packaged collection of reusable software components that other programs can depend on and call.

A library packages reusable software behind an API that other programs can call. Good libraries aim to be easy to use, difficult to misuse, correct, focused, and maintainable. section 6.0 section 6.12

Design a library by balancing:

  • User expectations and interface simplicity against unnecessary configuration or exposed surface area. section 6.1
  • Feature completeness, delivery speed, and implementation quality. section 6.1
  • Focused responsibilities, basic types, correctness checks, readable code, and backward compatibility. section 6.12

Publishing a linked-list library

Create a crate with `cargo new --lib linkedlist`, move the linked-list implementation into `src/lib.rs`, and test it from `tests/integration_test.rs`. External tests initially expose private types and methods; adding `pub` to the public structure, methods, and iterator types makes the crate usable while keeping fields private. section 6.11.1

#[test]
fn test_linkedlist() {
    use linkedlist::LinkedList;

    let mut linked_list = LinkedList::new("first item");     #1

    // ... snip ...
}

Shows an integration test importing and constructing the public `LinkedList` type from outside the crate. section 6.11.1

How Idiomatic Rust covers it

How deep it goes
Explains API tradeoffs and demonstrates Cargo setup, integration testing, visibility, documentation, and maintenance practices.
Examples
Uses a linked-list crate, external integration test, public iterator types, and compiler errors about private items.
What it assumes
Assumes familiarity with Rust code and linked lists while teaching library boundaries, visibility, integration tests, and user-oriented API design.
What you can do after
Build and maintain focused Rust libraries with usable APIs, external tests, correctness checks, and compatibility-conscious releases.
How it connects
Connects libraries with APIs, crates, Cargo, integration tests, visibility, documentation, property-based testing, fuzzing, Clippy, rustfmt, and semantic versioning.

Also explained in

Compare how 2 books explain library →

Related concepts

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