#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

#1134 in Text processing

Download history 10572/week @ 2024-07-29 10159/week @ 2024-08-05 12259/week @ 2024-08-12 11558/week @ 2024-08-19 16070/week @ 2024-08-26 11856/week @ 2024-09-02 13053/week @ 2024-09-09 12939/week @ 2024-09-16 16696/week @ 2024-09-23 16510/week @ 2024-09-30 15758/week @ 2024-10-07 14691/week @ 2024-10-14 11935/week @ 2024-10-21 17479/week @ 2024-10-28 17036/week @ 2024-11-04 26612/week @ 2024-11-11

73,822 downloads per month
Used in 12 crates (2 directly)

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