#string #embedded-devices #buffer #helper #firmware #type #encoding

no-std emstr

Helpers for working with string types for embedded devices

4 releases

0.2.0 Feb 6, 2023
0.1.2 Jan 23, 2023
0.1.1 Jan 22, 2023
0.1.0 Jan 20, 2023

#847 in Embedded development

24 downloads per month

MPL-2.0 license

22KB
533 lines

emstr

no_std and alloc-free string building and encoding for embedded firmware in rust.

This crate provides an EncodeStr trait for string encoding and implementations for basic types, as well as a write! macro for building strings from encodable objects, roughly equivalent to alloc::format! except using pre-allocated buffers.

Status

GitHub tag Build Status Crates.io Docs.rs


lib.rs:

Helpers for string concatenation / encoding / manipulation in an embedded no_std / alloc free environment

See [EncodeStr] for the base encode trait, and [write!] for constructing strings


// context can be any types implementing [emstr::EncodeStr]
let name = "something";
let progress = 15u8;

// use [emstr::write!]` macro to concatentate encodable types into `buff`
let mut buff = [0u8; 32];
let n = emstr::write!(&mut buff[..], name, ' ', progress, '/', 100u8).unwrap();

// creating the expected output
assert_eq!(&buff[..n], b"something 15/100");

Dependencies

~97–275KB