Crate hifmt

source ·
Expand description

hifmt - Format output without Rust code segment in binary

§Design objective:

  1. The print output depends on the API of C
  2. Eliminate the dependency on Display/Debug trait.

§Examples

extern crate hifmt;
#[link(name = "c")]
extern "C" {
    fn dprintf(fd: i32, format: *const u8, ...) -> i32;
    fn snprintf(buf: *mut u8, size: usize, format: *const u8, ...) -> i32;
}
hifmt::println!("hello world");
hifmt::println!("signed decimal {:d}", -1);
hifmt::println!("unsigned decimal {:u}", -1);
hifmt::println!("hexadecimal {:x}", -1);
hifmt::println!("pointer {:p}", &1);
hifmt::println!("float {:e}", -1.0);
hifmt::println!("rust &str {:rs}", "hello world");
hifmt::println!("rust &[u8] {:rb}", b"hello world");
hifmt::println!("rust char {:rc}", '中');
hifmt::println!("c str {:cs}", b"hello world\0");
hifmt::println!("c char {:cc}", b'0');

let mut buf = [0_u8; 100];
hifmt::bprint!(&mut buf, "snprintf rust string {:rs}", "hello world");
hifmt::println!("c str {:cs}", &buf);

Macros§

Functions§