mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 10:44:07 +02:00
impl FromStrProp for Color
This commit is contained in:
parent
28bdbf678d
commit
a32b9f060e
1 changed files with 16 additions and 0 deletions
|
|
@ -133,6 +133,7 @@ impl FromStrProp for u16 {}
|
|||
impl FromStrProp for f32 {}
|
||||
impl FromStrProp for u32 {}
|
||||
impl FromStrProp for i32 {}
|
||||
impl FromStrProp for Color {}
|
||||
impl FromStrProp for Vector {}
|
||||
|
||||
impl<T: FromStrProp> EntityProp<'_> for T
|
||||
|
|
@ -184,6 +185,21 @@ pub struct Color {
|
|||
pub b: u8,
|
||||
}
|
||||
|
||||
impl FromStr for Color {
|
||||
type Err = EntityParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let mut floats = s.split(' ').map(u8::from_str);
|
||||
let r = floats.next().ok_or(EntityParseError::ElementCount)??;
|
||||
let g = floats.next().ok_or(EntityParseError::ElementCount)??;
|
||||
let b = floats.next().ok_or(EntityParseError::ElementCount)??;
|
||||
if floats.next().is_some() {
|
||||
return Err(EntityParseError::ElementCount);
|
||||
}
|
||||
Ok(Self { r, g, b })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for Color {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue