Tokenize into enum instead of string

This commit is contained in:
hal8174 2025-08-25 21:16:27 +02:00
parent c48790f32f
commit b54a2b16fe
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
5 changed files with 376 additions and 340 deletions

View file

@ -14,9 +14,9 @@ pub(super) enum ImageMapWrap {
impl ImageMapWrap {
pub(super) fn new(x: String) -> Result<Self> {
match x.as_str() {
"\"repeat\"" => Ok(Self::Repeat),
"\"black\"" => Ok(Self::Black),
"\"clamp\"" => Ok(Self::Clamp),
"repeat" => Ok(Self::Repeat),
"black" => Ok(Self::Black),
"clamp" => Ok(Self::Clamp),
_ => Err(miette!("error image map wrap")),
}
}
@ -33,15 +33,11 @@ pub(super) enum ImageMapEncoding {
impl ImageMapEncoding {
pub(super) fn new(x: String) -> Result<Self> {
match x.as_str() {
"\"sRGB\"" => Ok(Self::SRGB),
"\"linear\"" => Ok(Self::Linear),
s if s.starts_with("\"gamma ") => Ok(Self::Gamma(
s.split_at(7)
.1
.trim_matches('\"')
.parse()
.into_diagnostic()?,
)),
"sRGB" => Ok(Self::SRGB),
"linear" => Ok(Self::Linear),
s if s.starts_with("gamma ") => {
Ok(Self::Gamma(s.split_at(7).1.parse().into_diagnostic()?))
}
_ => Err(miette!("error image map encoding")),
}
}