Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: fish-shell/printf-compat, 1 sao.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
This is a complete reimplementation of printf in Rust, using the unstable
(i.e. requires a Nightly compiler) c_variadic feature.
Many C libraries provide a way to provide a
custom log callback. With this crate, you can provide a pure Rust option,
and do whatever you want with it. Log it to the console, store it in a
string, or do anything else.
If you're writing a Rust-first program for a microcontroller and need to
interface with a C library, you might not have a libc and have to
reimplement it yourself. If it uses printf, use this crate to easily add
your own output. core::fmt too big? No problem! Write your own
formatting code, or use a minimal formatting library like ufmt or
defmt. Don't need every single option given by printf format
strings? No problem! Just don't implement it.
Likewise, if you're using wasm32-unknown-unknown instead of emscripten
(as wasm-bindgen is only compatible with the former), you have no libc. If
you want to interface with a C library, you'll have to do it all yourself.
With this crate, that turns into 5 lines instead of hundreds for printf.
Benefits
⚒ Modular
printf-compat lets you pick how you want to output a message. Use
pre-written adapters for fmt::Write (like a
String) or io::Write (like
io::stdout()), or implement your own.
🔬 Small
This crate is no_std compatible (printf-compat = { version = "0.1", default-features = false } in your Cargo.toml). The main machinery doesn't
require the use of core::fmt, and it can't panic.
🔒 Safe (as can be)
Of course, printf is completely unsafe, as it requires the use of
va_list. However, outside of that, all of the actual string parsing is
written in completely safe Rust. No buffer overflow attacks!
The n format specifier, which writes to a user-provided pointer, is
considered a serious security vulnerability if a user-provided string is
ever passed to printf. It is supported by this crate; however, it
doesn't do anything by default, and you'll have to explicitly do the writing
yourself.
🧹 Tested
A wide test suite is used to ensure that many different possibilities are
identical to glibc's printf. Differences are
documented.
If you're implenting printfbecause you don't have one, you'll want to
call it printf and add #[no_mangle].
Likewise, if you're creating a custom log function for a C library and it
expects to call a globally-defined function, keep #[no_mangle] and
rename the function to what it expects.
On the other hand, if your C library expects you to call a function to
register a callback (example 1, example 2),
remove #[no_mangle].
Now, add your logic:
use printf_compat::{format, output};
let mut s = String::new();
let bytes_written = format(str, args.as_va_list(), output::fmt_write(&mut s));
println!("{}", s);
bytes_written
Of course, replace output::fmt_write with whatever you like—some are
provided for you in output. If you'd like to write your own, follow
their function signature: you need to provide a function to format()
that takes an Argument and returns the number of bytes written (although
you don't need to if your C library doesn't use it) or -1 if there was an
error.
fish-shell/printf-compat có 1 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/fish-shell/printf-compat. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
fish-shell/printf-compat có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho fish-shell/printf-compat. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
fish-shell/printf-compat còn được duy trì không?
TopGit chưa ghi nhận lần push gần đây của fish-shell/printf-compat. Xem lịch sử commit trực tiếp trên GitHub để biết thông tin chính xác nhất.
fish-shell/printf-compat là gì?
fish-shell/printf-compat (fish-shell/printf-compat) là dự án đa ngôn ngữ TopGit theo dõi. Tính tới lần đồng bộ gần nhất, repo có 1 sao.
fish-shell/printf-compat viết bằng ngôn ngữ gì?
Dữ liệu TopGit chưa ghi nhận ngôn ngữ chính cho fish-shell/printf-compat. Xem danh sách file trên GitHub để biết chi tiết.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc printf-compat có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về printf-compat.