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

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

#2088 in Embedded development

Download history 3/week @ 2024-07-30 29/week @ 2024-08-06 10/week @ 2024-08-27 16/week @ 2024-09-03 1/week @ 2024-09-17 2/week @ 2024-09-24 10/week @ 2024-10-01

63 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

~94–255KB