quicklog_flush/
lib.rs

1//! ## `Flush` trait
2//!
3//! Simple trait that allows an underlying implementation of Flush to
4//! perform some type of IO operation, i.e. writing to file, writing to
5//! stdout, etc
6//!
7//! ## Example usage of `Flush`
8//!
9//! ```rust
10//! use quicklog_flush::Flush;
11//! # use quicklog_flush::stdout_flusher::StdoutFlusher;
12//! # use std::collections::VecDeque;
13//! # fn serialize_into_string(item: String) -> String { item }
14//! # struct Quicklog;
15//! impl Quicklog {
16//!     fn flush_logger(&mut self) {
17//!         # let mut flusher = StdoutFlusher::new();
18//!         # let mut queue = VecDeque::new();
19//!         # queue.push_back(String::from("Hello, world!"));
20//!         while let Some(item) = queue.pop_front() {
21//!             let log_string = serialize_into_string(item);
22//!             // flusher implements `Flush` trait
23//!             flusher.flush_one(log_string);
24//!         }
25//!     }
26//! }
27//! ```
28
29/// Flushes to a file
30pub mod file_flusher;
31/// No-op Flush, does nothing
32pub mod noop_flusher;
33/// Flushes to stdout through `print!` macro
34pub mod stdout_flusher;
35
36/// Simple trait that allows an underlying implementation of Flush to
37/// perform some type of IO operation, i.e. writing to file, writing to
38/// stdout, etc
39pub trait Flush {
40    /// Handles a string from another thread, and potentially performs I/O
41    /// operations such as writing to a file or to stdout
42    fn flush_one(&mut self, display: String);
43}