Crate binstring

Source
Expand description

A library for storing binary data as a string.

This library provides a BinString type that wraps a String and provides conversion methods between binary data and strings.

§Safety

While storing invalid UTF-8 in a String is perfectly safe, attempting to treat the string as valid UTF-8 (for example, by displaying it or using string operations that assume valid UTF-8) may lead to undefined behavior.

Most operations in this library work at the byte level and are safe to use with any binary data. However, some methods like trim() assume valid UTF-8 and should only be used when you are certain the data is valid UTF-8.

§Examples

use binstring::BinString;

// Create from a string
let bin_str = BinString::new("hello");
assert_eq!(bin_str.as_str(), "hello");

// Create from bytes
let bytes = vec![104, 101, 108, 108, 111]; // "hello" in bytes
let bin_str = BinString::from_bytes(bytes);
assert_eq!(bin_str.as_bytes(), &[104, 101, 108, 108, 111]);

Structs§

BinString
A type that wraps a String and provides conversion methods between binary data and strings.