tezvyn:

Rust binary and library crates in one project

Source: interviewintermediate

WHAT IT TESTS: crate structure and code reuse. OUTLINE: a binary crate has main and produces an executable; a library crate has lib.rs and is reusable; put logic in the lib and a thin main that calls it. RED FLAG: duplicating core logic inside main.rs.

WHAT IT TESTS: whether you separate reusable logic from a CLI entry point. ANSWER OUTLINE: a binary crate is rooted at main.rs with a main function and compiles to an executable; a library crate is rooted at lib.rs, has no main, and is meant to be depended on. A package can contain both, so you put all core logic in lib.rs and keep main.rs thin, calling the library, which makes the logic testable and reusable by others. RED FLAG: placing business logic in main.rs where it cannot be imported or unit-tested cleanly.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Rust binary and library crates in one project · Tezvyn