wfu 0.0.3

worksoup's formatting utilities
Documentation
  • Coverage
  • 18.42%
    7 out of 38 items documented7 out of 7 items with examples
  • Size
  • Source code size: 64.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 9.09 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • worksoup/wfu
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • worksoup

Worksoup's Formatting Utilities

Crates.io Documentation License

[dependencies]

wfu = "0.0.3"

use wfu::*;
use std::ops::Deref;


#[derive(Debug, Clone, Copy, Default)]
struct UppercaseProxy;
impl FmtHandler<&str> for UppercaseProxy {
    #[inline]
    fn fmt(&self, data: &&str, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
        for c in data.chars() {
            write!(f, "{}", c.to_uppercase())?;
        }
        Ok(())
    }
}
impl FmtHandler<str> for UppercaseProxy {
    #[inline]
    fn fmt(&self, data: &str, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
        for c in data.chars() {
            write!(f, "{}", c.to_uppercase())?;
        }
        Ok(())
    }
}
impl FmtHandler<String> for UppercaseProxy {
    #[inline(always)]
    fn fmt(&self, data: &String, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
        <Self as FmtHandler<str>>::fmt(self, data, f)
    }
}

fn main() {
    let s = "hello world";

    let result = format!("{}", s.fmt_as::<UppercaseProxy>());
    assert_eq!(result, "HELLO WORLD");
}

Provided

内置

use wfu::*;
 
let s = "hello";
let display_result = format!("{}", s.fmt_as::<DisplayProxy>());
let debug_result = format!("{}", s.fmt_as::<DebugProxy>());

let vec = vec!["a", "b", "c"];
// Joined
let joined = format!("{}", vec.fmt_by(Joined(", ")));
assert_eq!(joined, "a, b, c");

// Repeat
let stars = format!("{}", "*".fmt_by(Repeat(5)));
assert_eq!(stars, "*****");

闭包

use wfu::*;

let value = 42;
let holder = value.fmt_with(&|v, f| write!(f, "Value: {} ({:#x})", v, v));
let result = format!("{}", holder);
assert_eq!(result, "Value: 42 (0x2a)");