From 2eb60791bf11f14f55d30c5f6ae12fe254dd97bd Mon Sep 17 00:00:00 2001 From: Avril Date: Sat, 17 Dec 2022 08:51:30 +0000 Subject: [PATCH] Added logging for compile-time feature `status` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for day14's current commit: Blessing − 吉 --- day14/Cargo.lock | 135 ++++++++++++++++++++++++++++++++++++++++++++++ day14/Cargo.toml | 6 ++- day14/src/main.rs | 32 +++++++---- 3 files changed, 160 insertions(+), 13 deletions(-) diff --git a/day14/Cargo.lock b/day14/Cargo.lock index 449976e..477cecd 100644 --- a/day14/Cargo.lock +++ b/day14/Cargo.lock @@ -17,6 +17,26 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "backtrace" version = "0.3.67" @@ -64,6 +84,21 @@ dependencies = [ "color-eyre", "jemallocator", "linebuffer", + "log", + "pretty_env_logger", +] + +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", ] [[package]] @@ -88,6 +123,24 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "indenter" version = "0.3.3" @@ -125,6 +178,15 @@ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" name = "linebuffer" version = "0.1.0" +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + [[package]] name = "memchr" version = "2.5.0" @@ -161,8 +223,81 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger", + "log", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + [[package]] name = "rustc-demangle" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/day14/Cargo.toml b/day14/Cargo.toml index 9472b52..e59882c 100644 --- a/day14/Cargo.toml +++ b/day14/Cargo.toml @@ -17,11 +17,13 @@ inherits="release" strip=false [features] -default= [ "jemallocator" ] +default= ["jemallocator"] -status = ["jemallocator/profiling"] +status = ["jemallocator/profiling", "pretty_env_logger"] [dependencies] color-eyre = { version = "0.6.2", default-features = false } jemallocator = { version = "0.5.0", optional = true } linebuffer = { path = "/home/avril/work/linebuffer" } +log = "0.4.17" +pretty_env_logger = { version = "0.4.0", optional = true } diff --git a/day14/src/main.rs b/day14/src/main.rs index a1ebe54..3b64651 100644 --- a/day14/src/main.rs +++ b/day14/src/main.rs @@ -1,12 +1,11 @@ #![feature(repr_simd)] +#[macro_use] extern crate log; + use std::{ str, io, - iter::{ - self, - Fuse, - }, + iter, path::Path, }; @@ -33,10 +32,7 @@ const _:() = { }; mod ext { - use super::iter::{ - self, - FusedIterator, - }; + use super::iter::FusedIterator; #[derive(Debug, Clone)] pub struct TakeTwo(I); @@ -235,8 +231,17 @@ const INPUT_FILENAME: &'static str = "input"; /// Starting point of sand falling const ORIGIN_POINT: Point = Point { x: 500, y: 0 }; -fn main() -> eyre::Result<()> { +fn init() -> eyre::Result<()> +{ color_eyre::install()?; + #[cfg(feature="status")] + pretty_env_logger::init(); + + Ok(()) +} + +fn main() -> eyre::Result<()> { + init().wrap_err("Failed to install handlers and hooks")?; // Input let input = load_input_from(INPUT_FILENAME) @@ -246,9 +251,14 @@ fn main() -> eyre::Result<()> { let input = Input::parse(input) .wrap_err("Failed to parse input")?; + if cfg!(feature="status") { + debug!("Read {} zipped lines from input", input.zipped_len()); + + trace!("Input is:\n```{input:#?}```"); + } + + todo!("Deconstruction, draw, and simulation from `ORIGIN_POINT`"); //TODO: Deconstruct each `Line` into the horizontal and vertical movements - eprintln!("{input:#?}"); - println!("{}", input.zipped_len()); //TODO: Draw lines into grid before starting simulation of sand from `ORIGIN_POINT`.