diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-10-04 22:57:21 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-10-04 22:57:21 +0200 |
commit | 37e3c49f8eab5ceb1f4e1d3074d1badd34d7e463 (patch) | |
tree | d7904bb91bd63754777336b7c2ebe2a5191c2bf9 | |
parent | 4d457fa79a9bd37ccdfd45ce4fcca1d20d649f31 (diff) |
Add module for debug logging in iteratorslogging
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | src/lib.rs | 7 | ||||
-rw-r--r-- | src/logging.rs | 37 |
3 files changed, 52 insertions, 0 deletions
@@ -14,3 +14,11 @@ documentation = "https://docs.rs/resiter" repository = "https://github.com/matthiasbeyer/resiter" [dependencies] + +[dependencies.log] +version = "0.4" +optional = true + +[features] +default = [] +logging = ["log"] @@ -194,6 +194,13 @@ //! MPL 2.0 //! +#[cfg(feature = "logging")] +#[macro_use] +extern crate log; + +#[cfg(feature = "logging")] +pub mod logging; + pub mod and_then; pub mod errors; pub mod filter; diff --git a/src/logging.rs b/src/logging.rs new file mode 100644 index 0000000..32ca0b2 --- /dev/null +++ b/src/logging.rs @@ -0,0 +1,37 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +pub mod debug { + + pub trait IterDebug<'a, I, T> + where I: Iterator<Item = T> + { + fn debug(self, s: &'a str) -> DoIterDebug<'a, I, T>; + } + + impl<'a, I, T> IterDebug<'a, I, T> for I + where I: Iterator<Item = T> + { + fn debug(self, s: &'a str) -> DoIterDebug<'a, I, T> { + DoIterDebug(self, s) + } + } + + + pub struct DoIterDebug<'a, I, T>(I, &'a str) where I: Iterator<Item = T>; + + impl<'a, I, T> Iterator for DoIterDebug<'a, I, T> + where I: Iterator<Item = T> + { + type Item = T; + + fn next(&mut self) -> Option<Self::Item> { + debug!("{}", self.1); + self.0.next() + } + } + +} |