Giter Site home page Giter Site logo

sprintf-rs's Introduction

sprintf-rs

a clone of C sprintf in Rust

This crate was created out of a desire to provide C printf-style formatting in a WASM program, where there is no libc.

Note: You're probably better off using standard Rust string formatting instead of this crate unless you specificaly need printf compatibility.

This crate implements a dynamically type-checked function vsprintf and macro sprintf!.

Usage example:

use sprintf::sprintf;
let s = sprintf!("%d + %d = %d\n", 3, 9, 3+9).unwrap();
assert_eq!(s, "3 + 9 = 12\n");

libc is a dev dependency as it is used in the tests to compare results. std is used for some maths functions.

sprintf-rs's People

Contributors

dabs avatar flaviojs avatar pierd avatar tjol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sprintf-rs's Issues

"%.1f" of 999.99 => "999.0"

Incorrect rounding of floating point numbers:

sprintf!("%.1f",999.99).unwrap() == "999.0"

should be "1000.0"

Print pointer addresses

I'm converting a printf-like call from C to rust that uses %p to print the address of a pointer but currently pointers are not supported in this library.

The p conversion type is parsed and the address of a pointer is safe data so it should be fine to accept a pointer.
Is this the case? I can make a PR.

Alternatively maybe you want users to require an explicit cast to usize (or .addr() with strict_provenance).
Is this the case? If so, the docs should be updated to reflect that.

Support C string types

I tried to use this crate with C string pointers but failed.

Are you ok with implementing sprintf::Printf for:

  • std::ffi::CStr
  • std::ffi::CString
  • *const c_char
  • *mut c_char
  • c_char too if possible

I don't mind having to enable a feature flag.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.