icydb_base/validator/
bytes.rs

1use crate::{core::traits::Validator, prelude::*};
2
3///
4/// Utf8
5///
6
7#[validator]
8pub struct Utf8;
9
10impl Validator<[u8]> for Utf8 {
11    fn validate(&self, bytes: &[u8]) -> Result<(), String> {
12        std::str::from_utf8(bytes)
13            .map(|_| ())
14            .map_err(|_| "invalid utf-8 data".to_string())
15    }
16}