1
2
3
4
5
6
7
8
9
10
11
12
use std::num::NonZeroU8;

use crate::{Error, KeyName};

pub fn validate<K: KeyName + ?Sized>(s: &str) -> Result<NonZeroU8, Error> {
    let colon_idx =
        NonZeroU8::new(s.find(':').ok_or(Error::MissingColon)? as u8).ok_or(Error::MissingColon)?;

    K::validate(&s[colon_idx.get() as usize + 1..])?;

    Ok(colon_idx)
}