Debian Codegraph @

README.md

raw symbols SCIP
1 # no_std libc print/println/eprint/eprintln/dbg
2
3 ![Build Status](https://github.com/mmastrac/rust-libc-print/actions/workflows/rust.yml/badge.svg)
4 [![docs.rs](https://docs.rs/libc-print/badge.svg)](https://docs.rs/libc-print)
5 [![crates.io](https://img.shields.io/crates/v/libc-print.svg)](https://crates.io/crates/libc-print)
6
7 Implements `println!`, `eprintln!` and `dbg!` on the `libc` crate without
8 requiring the use of an allocator.
9
10 Allows you to use these macros in a `#![no_std]` context, or in a
11 situation where the traditional Rust streams might not be available
12 (ie: at process shutdown time).
13
14 By default this crate provides `libc_`-prefixed macros, but also allows consumers to
15 import macros with the same name as the stdlib printing macros via the `std_name`
16 module.
17
18 ## Platform Support
19
20 For platforms with `write` in libc, this crate uses `libc::write`. For `unknown`
21 and `none` OS targets, the user is required to provide a `write` function via
22 the linker.
23
24 This crate support `miri` on all platforms, though it may choose different code
25 paths for compatibility reasons.
26
27 ## Usage
28
29 Exactly as you'd use `println!`, `eprintln!` and `dbg!`.
30
31 ```rust
32 #![no_std]
33
34 // Use the default `libc_`-prefixed macros:
35 libc_println!("Hello {}!", "stdout");
36 libc_eprintln!("Hello {}!", "stderr");
37 let a = 2;
38 let b = libc_dbg!(a * 2) + 1;
39 assert_eq!(b, 5);
40 ```
41
42 Or you can import aliases to `std` names:
43
44 ```rust
45 use libc_print::std_name::{println, eprintln, dbg};
46
47 println!("Hello {}!", "stdout");
48 eprintln!("Hello {}!", "stderr");
49 let a = 2;
50 let b = dbg!(a * 2) + 1;
51 assert_eq!(b, 5);
52 ```