set_var_format

This commit is contained in:
Martin Kavík 2024-06-09 22:53:02 +02:00
parent d654714c0d
commit 1881d62c56
11 changed files with 145 additions and 35 deletions

View file

@ -1,4 +1,7 @@
#[derive(Default, Clone, Copy, Debug)]
use moonlight::*;
#[derive(Default, Clone, Copy, Debug, Serialize, Deserialize)]
#[serde(crate = "serde")]
pub enum VarFormat {
ASCII,
Binary,
@ -55,12 +58,14 @@ impl VarFormat {
}
VarFormat::Binary => value,
VarFormat::BinaryWithGroups => {
let char_count = value.len();
value
.chars()
.enumerate()
.fold(String::new(), |mut value, (index, one_or_zero)| {
value.push(one_or_zero);
if (index + 1) % 4 == 0 {
let is_last = index == char_count - 1;
if !is_last && (index + 1) % 4 == 0 {
value.push(' ');
}
value