Writing and testing a crate – logic gate simulator

Armed with all of this knowledge, let's start things off with our logic gate simulation crate. We'll create a new project by running cargo new logic_gates --lib. Starting with primitive gates implemented as functions such as and, xor, and so on, we will write unit tests for these gates. Following that, we'll write integration tests by implementing a half adder that uses our primitive gates. During this process, we'll also get to write documentation for our crate.

First off, we'll start with some unit tests. Here's the initial crate code in its entirety:

//! This is a logic gates simulation crate built to demonstrate writing unit tests and integration tests// logic_gates/src/lib.rspub fn ...

Get Mastering Rust - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.