#mocking #networking #injectable #resources #abstraction #file

kxio

Provides injectable Filesystem and Network resources to make code more testable

15 stable releases (5 major)

5.1.0 Jan 18, 2025
5.0.0 Dec 29, 2024
4.0.1 Dec 25, 2024
3.2.0 Dec 12, 2024
0.1.2 Apr 10, 2024

#144 in Filesystem

Download history 15/week @ 2024-10-05 13/week @ 2024-10-12 57/week @ 2024-10-19 23/week @ 2024-10-26 42/week @ 2024-11-02 278/week @ 2024-11-09 496/week @ 2024-11-16 200/week @ 2024-11-23 76/week @ 2024-11-30 489/week @ 2024-12-07 463/week @ 2024-12-14 248/week @ 2024-12-21 442/week @ 2024-12-28 316/week @ 2025-01-04 547/week @ 2025-01-11 242/week @ 2025-01-18

1,583 downloads per month
Used in 6 crates

MIT license

105KB
1.5K SLoC

kxio

kxio is a Rust library that provides injectable FileSystem, Network and Print resources to enhance the testability of your code. By abstracting system-level interactions, kxio enables easier mocking and testing of code that relies on file system and network operations.

Features

  • Filesystem Abstraction
  • Network Abstraction
  • Print Abstraction
  • Enhanced Testability

Filesystem

The Filesystem module offers a clean abstraction over std::fs, the standard file system operations. For comprehensive documentation and usage examples, please refer to https://docs.rs/kxio/latest/kxio/fs/.

Key Filesystem Features:

  • File reading and writing
  • Directory operations
  • File metadata access
  • Fluent API for operations like .reader().bytes()

Network

The Network module offers a testable interface over the reqwest crate. For comprehensive documentation and usage examples, please refer to 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

Add kxio to your Cargo.toml:

[dependencies]
kxio = "x.y.z"

Usage

See the example get.rs for an annotated example on how to use the kxio library. It covers both the net and fs modules.

Development

Contributing

Contributions are welcome! Please check our issue tracker for open tasks or submit your own ideas.

License

This project is licensed under the terms specified in the LICENSE file in the repository root.

Acknowledgements

  • Built with Rust

For more information, bug reports, or feature requests, please visit our repository.

Dependencies

~8–22MB
~319K SLoC