From 19c26ff3a05e3af0cb88c5f5ac5799e57dbf021c Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 30 Nov 2020 15:15:54 -0800 Subject: Initial Rust stuff --- lib/Cargo.toml | 7 +++++++ lib/src/error.rs | 30 ++++++++++++++++++++++++++++++ lib/src/lib.rs | 11 +++++++++++ lib/src/prelude.rs | 4 ++++ 4 files changed, 52 insertions(+) create mode 100644 lib/Cargo.toml create mode 100644 lib/src/error.rs create mode 100644 lib/src/lib.rs create mode 100644 lib/src/prelude.rs (limited to 'lib') 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 "] +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 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 = std::result::Result; + -- cgit 1.4.1