Giter Club home page Giter Club logo

arrform's Introduction

String formatting without memory allocator

In bare matal systems, there is often the task of converting numbers into text and formatting them. The standard Rust functions like format!, write! etc. cannot be used in no_std environments because they require a memory allocator. The arrform! macro uses the standard library functions, but writes to a fixed length array which is alocated on the stack.

This crate is usable in no_std environments. This is a replacement for the format! macro, based on a fixed-size array allocated on the stack.

arrform!

use arrform::{arrform, ArrForm};

let af = arrform!(64, "write some stuff {}: {:.2}", "foo", 42.3456);
assert_eq!("write some stuff foo: 42.35", af.as_str());

ArrForm struct as an alternative

The ArrForm struct provides more detailed error handling and supports multiple use of the same buffer. However, it is much more cumbersome to use and generates more syntactic noise.

Overhead

The convenient option to format can cost a lot of storage space. On a Cortex M4 992 bytes of program code are needed additionally, if instead of a simple string a simple u32 number is embedded with the help of the macro. It becomes even more expensive if f32 numbers are output formatted (30,928 bytes additional). The program code used to determine these numbers can be found in the example directory.

License

Apache version 2.0 or Mit

arrform's People

Contributors

simsys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.