I wrote an application that iterates over a reference to [u8] vector.
Just as simple as this:
#![allow(unused)]
use std::char;
fn main() {
let vsparkle_heart = &[240, 159, 119, 150];
let mut ic: usize = 0;
let mut sasciiheart = String::with_capacity(vsparkle_heart.len());
for uc in vsparkle_heart {
print!(
"; {} - {}:'{}', {:?}",
ic,
uc,
char::from(*uc),
(*uc >= 32 as u8 && *uc < 127 as u8) || (*uc == 10 as u8)
);
if (*uc >= 32 as u8 && *uc < 127 as u8) || (*uc == 10 as u8) {
print!(" - ascii");
//Add the valid ASCII Character
sasciiheart.push(char::from(*uc));
} else {
print!(" - non-ascii");
}
ic += 1;
}
print!("; chr cnt: '{}'", ic);
println!("\nascii: '{}'", &sasciiheart);
}
this works very nice on the Playground:
Standard Error
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 1.80s
Running `target/debug/playground`
Standard Output
; 0 - 240:'ð', false - non-ascii; 1 - 159:'', false - non-ascii; 2 - 119:'w', true - ascii; 3 - 150:'', false - non-ascii; chr cnt: '4'
ascii: 'w'
but when I run it on my local system it stops writing the output at some point:
ASCII Heart Example
$ cargo run --example ascii-heart
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/examples/ascii-heart`
; 0 - 240:'ð', false - non-ascii; 1 - 159:'', false - non-ascii; chr cnt: '4'
ascii: 'w'
so it seems as if it has done the whole cycle but on finding the u8
= "119" it just stopped writing the output.
Also writing the output to a report String
shows the same behaviour.
This is a bad roadblock when troubleshooting complex data.
And I wonder if someone can offer some insight about this.