Tokenize into enum instead of string
This commit is contained in:
parent
c48790f32f
commit
b54a2b16fe
5 changed files with 376 additions and 340 deletions
|
|
@ -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")),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue