| Crates.io | lwprintf-rs |
| lib.rs | lwprintf-rs |
| version | 0.3.2 |
| created_at | 2025-12-08 04:17:01.182731+00 |
| updated_at | 2026-01-03 11:46:53.289014+00 |
| description | Rust bindings for the lightweight printf library lwprintf. |
| homepage | https://github.com/Godones/lwprintf-rs |
| repository | https://github.com/Godones/lwprintf-rs |
| max_upload_size | |
| id | 1972714 |
| size | 4,261,346 |
Lightweight printf bindings for Rust, powered by the upstream C library lwprintf. Provides no_std support and minimal glue to hook custom output sinks from Rust.
cc and generates bindings via bindgen at compile time.lwprintf_printf_ex, lwprintf_vprintf_ex, lwprintf_snprintf_ex, lwprintf_vsnprintf_ex) plus Rust helpers and macros.CustomOutPut trait and LwprintfObj wrapper.CustomOutPut { fn putch(ch: i32) -> i32; } – implement to handle each output byte/char.LwprintfObj<T: CustomOutPut>
new() – create an instance (uninitialized).as_mut_ptr() – get *mut lwprintf_t for calling the raw C FFI.lwprintf_printf_ex, lwprintf_vprintf_exlwprintf_snprintf_ex, lwprintf_vsnprintf_exVaList to the raw APIs):
lwprintf_vprintf_ex_rust, lwprintf_vsnprintf_ex_rustlwobj):
lwprintf_printf!, lwprintf_vprintf!lwprintf_snprintf!, lwprintf_vsnprintf!lwprintf_sprintf!, lwprintf_sprintf_ex!cargo run --example print
use lwprintf_rs::{CustomOutPut, LwprintfObj};
struct StdOut;
impl CustomOutPut for StdOut {
fn putch(ch: i32) -> i32 { print!("{}", ch as u8 as char); ch }
}
fn main() {
let mut lw = LwprintfObj::<StdOut>::new();
lwprintf_rs::lwprintf_init_ex(&mut lw);
unsafe {
// Call the raw C varargs API using the object pointer
lwprintf_rs::lwprintf_printf_ex(
lw.as_mut_ptr(),
b"Hello %s %d!\n\0".as_ptr() as *const i8,
b"world\0".as_ptr() as *const i8,
42,
);
}
}
lwprintf_printf_ex etc.) and pass the pointer from as_mut_ptr().va_list-style calls, prefer lwprintf_vprintf_ex / lwprintf_vsnprintf_ex or the Rust helpers lwprintf_vprintf_ex_rust / lwprintf_vsnprintf_ex_rust which forward a VaList to C.lwprintf.c and generates bindings on the fly. No pre-generated bindings are checked in.clang and a C toolchain are available for bindgen/cc.no_std environments, but requires a musl toolchain. When compiling the lwprintf C code, musl's gcc is needed to set the correct sysroot and handle missing headers.Rust cannot preserve the original C varargs ABI layout when re-forwarding ... across Rust functions. A Rust wrapper that takes ... and then forwards to another ... function will corrupt the call frame. Always call the raw C varargs functions directly (or use va_list variants) once arguments are marshalled.