From f635b2667115abebe17a5dff516bd5420b34986c Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Thu, 10 Dec 2015 14:35:41 -0500 Subject: [PATCH] Update readme and another tutorial --- README.md | 2 ++ adder/Cargo.lock | 4 ++++ adder/Cargo.toml | 4 ++++ adder/src/lib.rs | 30 ++++++++++++++++++++++++++++++ adder/tests/lib.rs | 6 ++++++ 5 files changed, 46 insertions(+) create mode 100644 adder/Cargo.lock create mode 100644 adder/Cargo.toml create mode 100644 adder/src/lib.rs create mode 100644 adder/tests/lib.rs diff --git a/README.md b/README.md index 05da6ae..aa22e43 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # literate-tribble + +## Rust toy programs and tutorials diff --git a/adder/Cargo.lock b/adder/Cargo.lock new file mode 100644 index 0000000..b8db25a --- /dev/null +++ b/adder/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "adder" +version = "0.1.0" + diff --git a/adder/Cargo.toml b/adder/Cargo.toml new file mode 100644 index 0000000..c781658 --- /dev/null +++ b/adder/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "adder" +version = "0.1.0" +authors = ["Tim Warren "] diff --git a/adder/src/lib.rs b/adder/src/lib.rs new file mode 100644 index 0000000..23f8804 --- /dev/null +++ b/adder/src/lib.rs @@ -0,0 +1,30 @@ +//! The `adder` crate provides functions that add numbers to other numbers +//! +//! # Examples +//! +//! ``` +//! assert_eq!(4, adder::add_two(2)); +//! ``` + +/// This function adds two to its argument +/// +/// # Examples +/// +/// ``` +/// use adder::add_two; +/// +/// assert_eq!(4, add_two(2)); +/// ``` +pub fn add_two(a: i32) -> i32 { + a + 2 // return +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + assert_eq!(4, add_two(2)); + } +} \ No newline at end of file diff --git a/adder/tests/lib.rs b/adder/tests/lib.rs new file mode 100644 index 0000000..3044b73 --- /dev/null +++ b/adder/tests/lib.rs @@ -0,0 +1,6 @@ +extern crate adder; + +#[test] +fn it_works() { + assert_eq!(4, adder::add_two(2)); +} \ No newline at end of file