docs(print): add details to readme and an example
This commit is contained in:
parent
8007f01d94
commit
1c5a1bdb69
3 changed files with 31 additions and 4 deletions
30
README.md
30
README.md
|
@ -1,14 +1,15 @@
|
||||||
# kxio
|
# kxio
|
||||||
|
|
||||||
`kxio` is a Rust library that provides injectable `FileSystem` and `Network`
|
`kxio` is a Rust library that provides injectable `FileSystem`, `Network` and
|
||||||
resources to enhance the testability of your code. By abstracting system-level
|
`Print` resources to enhance the testability of your code. By abstracting
|
||||||
interactions, `kxio` enables easier mocking and testing of code that relies on
|
system-level interactions, `kxio` enables easier mocking and testing of code
|
||||||
file system and network operations.
|
that relies on file system and network operations.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Filesystem Abstraction**
|
- **Filesystem Abstraction**
|
||||||
- **Network Abstraction**
|
- **Network Abstraction**
|
||||||
|
- **Print Abstraction**
|
||||||
- **Enhanced Testability**
|
- **Enhanced Testability**
|
||||||
|
|
||||||
## Filesystem
|
## Filesystem
|
||||||
|
@ -30,6 +31,27 @@ The Network module offers a testable interface over the `reqwest` crate. For
|
||||||
comprehensive documentation and usage examples, please refer to
|
comprehensive documentation and usage examples, please refer to
|
||||||
<https://docs.rs/kxio/latest/kxio/net/>
|
<https://docs.rs/kxio/latest/kxio/net/>
|
||||||
|
|
||||||
|
## Print
|
||||||
|
|
||||||
|
The Print module provides three implementations of the `Printer` trait:
|
||||||
|
|
||||||
|
- `StandardPrint` - behaves as normal, printing to `STDOUT` and `STDERR`
|
||||||
|
- `NullPrint` - swallows all prints, outputting nothing
|
||||||
|
- `TestPrint` - captures all print output and makes it available for assertions in tests
|
||||||
|
|
||||||
|
It also provides macros to use with each:
|
||||||
|
|
||||||
|
- `kxprintln`
|
||||||
|
- `kxprint`
|
||||||
|
- `kxeprintln`
|
||||||
|
- `kxeprint`
|
||||||
|
|
||||||
|
They are analogous to the `std` macros: `println`, `print`, `eprintln` and `eprint` respectively.
|
||||||
|
|
||||||
|
Each of the `kx{e}print{ln}` macros takes a reference to an instance of the `Printer` trait as the first parameter.
|
||||||
|
|
||||||
|
For comprehensive documentation and usage examples, please refer to <https://docs.rs/kxio/latest/kxio/print/>
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
Add `kxio` to your `Cargo.toml`:
|
Add `kxio` to your `Cargo.toml`:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/// Macro to print the expression to the `Printer` with a trailing newline.
|
||||||
|
///
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! kxprintln {
|
macro_rules! kxprintln {
|
||||||
($printer:expr, $($arg:tt)*) => {{
|
($printer:expr, $($arg:tt)*) => {{
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use kxio::print::{Print, StandardPrint};
|
//! use kxio::print::{Print, StandardPrint};
|
||||||
|
//! use kxio::{kxeprintln, kxprintln};
|
||||||
//!
|
//!
|
||||||
//! fn print_hello(printer: &impl Print) {
|
//! fn print_hello(printer: &impl Print) {
|
||||||
//! printer.println("Hello, World!");
|
//! printer.println("Hello, World!");
|
||||||
|
@ -18,6 +19,8 @@
|
||||||
//!
|
//!
|
||||||
//! let printer = StandardPrint;
|
//! let printer = StandardPrint;
|
||||||
//! print_hello(&printer);
|
//! print_hello(&printer);
|
||||||
|
//! kxprintln!(&printer, "Hello, world!");
|
||||||
|
//! kxeprintln!(&printer, "Terminating!");
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
Loading…
Reference in a new issue