-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathstreaming.rs
More file actions
34 lines (29 loc) · 990 Bytes
/
streaming.rs
File metadata and controls
34 lines (29 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[allow(unused_imports)]
use std::io::{stdin, Read, Result};
#[cfg(all(feature = "public_imp", target_arch = "x86_64"))]
fn main() -> Result<()> {
use simdutf8::basic::imp::Utf8Validator;
unsafe {
if !std::is_x86_feature_detected!("avx2") {
panic!("This example only works with CPUs supporting AVX 2");
}
let mut validator = simdutf8::basic::imp::x86::avx2::Utf8ValidatorImp::new();
let mut buf = vec![0; 8192];
loop {
let bytes_read = stdin().read(buf.as_mut())?;
if bytes_read == 0 {
break;
}
validator.update(&buf);
}
if validator.finalize().is_ok() {
println!("Input is valid UTF-8");
} else {
println!("Input is not valid UTF-8");
}
}
Ok(())
}
/// Dummy main. This example requires the crate feature `public_imp`.
#[cfg(not(all(feature = "public_imp", target_arch = "x86_64")))]
fn main() {}