#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

#1207 in Text processing

Download history 1649/week @ 2024-01-11 2253/week @ 2024-01-18 1943/week @ 2024-01-25 2524/week @ 2024-02-01 1364/week @ 2024-02-08 2154/week @ 2024-02-15 1605/week @ 2024-02-22 2318/week @ 2024-02-29 3032/week @ 2024-03-07 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 8657/week @ 2024-04-25

44,106 downloads per month
Used in 5 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