#string #write #macro #formatting #writeln

swrite

Infallible alternatives to write! and writeln! for Strings

3 unstable releases

Uses old Rust 2015

0.1.0 Apr 8, 2023
0.0.2 Apr 8, 2023
0.0.1 Apr 6, 2023

#1169 in Text processing

Download history 9487/week @ 2024-03-14 11828/week @ 2024-03-21 8598/week @ 2024-03-28 12904/week @ 2024-04-04 10362/week @ 2024-04-11 10367/week @ 2024-04-18 10910/week @ 2024-04-25 8471/week @ 2024-05-02 10902/week @ 2024-05-09 10394/week @ 2024-05-16 8229/week @ 2024-05-23 11354/week @ 2024-05-30 10678/week @ 2024-06-06 9093/week @ 2024-06-13 14486/week @ 2024-06-20 9027/week @ 2024-06-27

46,443 downloads per month
Used in 11 crates (via cargo-nextest)

MIT/Apache

9KB
78 lines

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.

No runtime deps

Features