swrite 0.1.0

Infallible alternatives to write! and writeln! for Strings
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented3 out of 6 items with examples
  • Size
  • Source code size: 20.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 274.93 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • rusticstuff/swrite
    3 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hkratz

swrite

CI crates.io docs.rs Minimum rustc version

swrite is a tiny Rust crate providing the swrite! and swriteln! macros as infallible alternatives to write! and writeln! for Strings. This is safe because writing to a String never returns Err(_).

The implementation uses the SWrite trait. It is implemented for String. With the osstring feature is enabled, it is also implemented for std::ffi::OsString.

Minimum Supported Rust Version (MSRV):

  • Without the osstring feature (default): 1.30.0
  • With the osstring feature: 1.64.0

Usage

In Cargo.toml:

[dependencies]
swrite = "0.1.0"

In your Rust code:

use swrite::{SWrite, swrite, swriteln};

Examples

Using swrite! and swriteln! with a String:

use swrite::{SWrite, swrite, swriteln};

let mut s = String::new();
swrite!(s, "Hello, {}! ", "world");
swriteln!(s, "The answer is {}.", 42);

println!("{}", s);

Output:

Hello, world! The answer is 42.

License

This project is dual-licensed under Apache 2.0 and MIT licenses.