app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 1f0fe381dba78e85fa4a5fc244c61816d9b4efca
parent d78a2f0f8d27502074a4311ff5be29df4fc84021
Author: triesap <triesap@radroots.dev>
Date:   Mon, 19 Jan 2026 06:48:24 +0000

app-utils: add text encoding helpers

- add text_enc to encode strings to bytes
- add text_dec to decode bytes to string
- export text encode and decode helpers
- add roundtrip unit test coverage

Diffstat:
Mcrates/utils/src/lib.rs | 2+-
Mcrates/utils/src/text/mod.rs | 18+++++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs @@ -6,5 +6,5 @@ pub mod text; pub mod types; pub use errors::{err_msg, handle_err, throw_err, ERR_PREFIX_APP, ERR_PREFIX_UTILS}; -pub use text::ROOT_SYMBOL; +pub use text::{text_dec, text_enc, ROOT_SYMBOL}; pub use types::{resolve_err, resolve_ok, ResolveError, ResultPass}; diff --git a/crates/utils/src/text/mod.rs b/crates/utils/src/text/mod.rs @@ -2,12 +2,28 @@ pub const ROOT_SYMBOL: &str = "»`,-"; +pub fn text_enc(data: &str) -> Vec<u8> { + data.as_bytes().to_vec() +} + +pub fn text_dec(data: &[u8]) -> String { + String::from_utf8_lossy(data).to_string() +} + #[cfg(test)] mod tests { - use super::ROOT_SYMBOL; + use super::{text_dec, text_enc, ROOT_SYMBOL}; #[test] fn root_symbol_matches_spec() { assert_eq!(ROOT_SYMBOL, "»`,-"); } + + #[test] + fn text_enc_dec_roundtrip() { + let encoded = text_enc("radroots"); + assert_eq!(encoded, b"radroots"); + let decoded = text_dec(&encoded); + assert_eq!(decoded, "radroots"); + } }