Debian Codegraph @

README.md

raw symbols SCIP
1 # swrite
2
3 [![CI](https://github.com/rusticstuff/swrite/actions/workflows/ci.yml/badge.svg)](https://github.com/rusticstuff/swrite/actions/workflows/ci.yml)
4 [![crates.io](https://img.shields.io/crates/v/swrite.svg)](https://crates.io/crates/swrite)
5 [![docs.rs](https://docs.rs/swrite/badge.svg)](https://docs.rs/swrite)
6 ![Minimum rustc version](https://img.shields.io/badge/rustc-1.30+-lightgray.svg)
7
8 `swrite` is a tiny Rust crate providing the `swrite!` and `swriteln!` macros as
9 infallible alternatives to `write!` and `writeln!` for Strings. This is safe because
10 writing to a String never returns `Err(_)`.
11
12 The implementation uses the `SWrite` trait. It is implemented for `String`.
13 With the `osstring` feature is enabled, it is also implemented for `std::ffi::OsString`.
14
15 Minimum Supported Rust Version (MSRV):
16 - Without the `osstring` feature (default): 1.30.0
17 - With the `osstring` feature: 1.64.0
18
19 ## Usage
20
21 In `Cargo.toml`:
22
23 ```toml
24 [dependencies]
25 swrite = "0.1.0"
26 ```
27
28 In your Rust code:
29
30 ```rust
31 use swrite::{SWrite, swrite, swriteln};
32 ```
33
34 ## Examples
35
36 Using `swrite!` and `swriteln!` with a `String`:
37
38 ```rust
39 use swrite::{SWrite, swrite, swriteln};
40
41 let mut s = String::new();
42 swrite!(s, "Hello, {}! ", "world");
43 swriteln!(s, "The answer is {}.", 42);
44
45 println!("{}", s);
46 ```
47
48 Output:
49
50 ```not_rust
51 Hello, world! The answer is 42.
52 ```
53
54 ## License
55
56 This project is dual-licensed under [Apache 2.0](LICENSE-APACHE) and [MIT](LICENSE-MIT) licenses.