Debian Codegraph @

examples/streaming.rs

raw symbols SCIP
1 #[allow(unused_imports)]
2 use std::io::{stdin, Read, Result};
3
4 #[cfg(all(
5 feature = "public_imp",
6 any(target_arch = "x86", target_arch = "x86_64")
7 ))]
8 fn main() -> Result<()> {
9 use simdutf8::basic::imp::Utf8Validator;
10
11 unsafe {
12 if !std::is_x86_feature_detected!("avx2") {
13 panic!("This example only works with CPUs supporting AVX 2");
14 }
15
16 let mut validator = simdutf8::basic::imp::x86::avx2::Utf8ValidatorImp::new();
17 let mut buf = vec![0; 8192];
18 loop {
19 let bytes_read = stdin().read(buf.as_mut())?;
20 if bytes_read == 0 {
21 break;
22 }
23 validator.update(&buf);
24 }
25
26 if validator.finalize().is_ok() {
27 println!("Input is valid UTF-8");
28 } else {
29 println!("Input is not valid UTF-8");
30 }
31 }
32
33 Ok(())
34 }
35
36 /// Dummy main. This example requires the crate feature `public_imp`.
37 #[cfg(not(all(
38 feature = "public_imp",
39 any(target_arch = "x86", target_arch = "x86_64")
40 )))]
41 fn main() {}