diff options
-rw-r--r-- | 01/Cargo.toml | 8 | ||||
-rw-r--r-- | 01/src/main.rs | 8 | ||||
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | lib/Cargo.toml | 7 | ||||
-rw-r--r-- | lib/src/error.rs | 30 | ||||
-rw-r--r-- | lib/src/lib.rs | 11 | ||||
-rw-r--r-- | lib/src/prelude.rs | 4 |
8 files changed, 85 insertions, 0 deletions
diff --git a/01/Cargo.toml b/01/Cargo.toml new file mode 100644 index 0000000..e9379e7 --- /dev/null +++ b/01/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "advent_01" +version = "0.1.0" +authors = ["Irene Knapp <ireneista@gmail.com>"] +edition = "2018" + +[dependencies] +advent_lib = { path = "../lib" } diff --git a/01/src/main.rs b/01/src/main.rs new file mode 100644 index 0000000..480e6db --- /dev/null +++ b/01/src/main.rs @@ -0,0 +1,8 @@ +use advent_lib::prelude::*; + + +fn main() -> Result<()> { + advent_lib::greeting()?; + + Ok(()) +} diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..494a001 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,12 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "advent_01" +version = "0.1.0" +dependencies = [ + "advent_lib", +] + +[[package]] +name = "advent_lib" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2446b10 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] +members = [ + "lib", + "01", +] diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..f0a0859 --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "advent_lib" +version = "0.1.0" +authors = ["Irene Knapp <ireneista@gmail.com>"] +edition = "2018" + +[dependencies] diff --git a/lib/src/error.rs b/lib/src/error.rs new file mode 100644 index 0000000..cd4a760 --- /dev/null +++ b/lib/src/error.rs @@ -0,0 +1,30 @@ +#[derive(Debug)] +pub enum Error { + IO(std::io::Error), +} + +impl std::error::Error for Error { } + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::IO(e) => e.fmt(f), + } + } +} + +impl std::cmp::PartialEq for Error { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Error::IO(_), Error::IO(_)) => + false, + } + } +} + +impl From<std::io::Error> for Error { + fn from(e: std::io::Error) -> Error { + Error::IO(e) + } +} + diff --git a/lib/src/lib.rs b/lib/src/lib.rs new file mode 100644 index 0000000..b198f10 --- /dev/null +++ b/lib/src/lib.rs @@ -0,0 +1,11 @@ +pub mod error; +pub mod prelude; + +pub use crate::prelude::Result; + + +pub fn greeting() -> Result<()> { + println!("Hello, Irenes!"); + + Ok(()) +} diff --git a/lib/src/prelude.rs b/lib/src/prelude.rs new file mode 100644 index 0000000..a4e81eb --- /dev/null +++ b/lib/src/prelude.rs @@ -0,0 +1,4 @@ +use crate::error::Error; + +pub type Result<T> = std::result::Result<T, Error>; + |