mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
remove EntityParseError::NoSuchProperty
Optional semantics should not be folded into the error type.
This commit is contained in:
parent
3858ba46de
commit
bfc70d63cd
2 changed files with 6 additions and 6 deletions
|
|
@ -102,14 +102,16 @@ impl<'a> RawEntity<'a> {
|
||||||
Iter { buf: self.buf }
|
Iter { buf: self.buf }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prop(&self, key: &'static str) -> Result<&'a str, EntityParseError> {
|
pub fn prop(&self, key: &'static str) -> Option<&'a str> {
|
||||||
self.properties()
|
self.properties()
|
||||||
.find_map(|(prop_key, value)| (key == prop_key).then_some(value))
|
.find_map(|(prop_key, value)| (key == prop_key).then_some(value))
|
||||||
.ok_or(EntityParseError::NoSuchProperty(key))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prop_parse<T: EntityProp<'a>>(&self, key: &'static str) -> Result<T, EntityParseError> {
|
pub fn prop_parse<T: EntityProp<'a>>(
|
||||||
T::parse(self.prop(key)?)
|
&self,
|
||||||
|
key: &'static str,
|
||||||
|
) -> Option<Result<T, EntityParseError>> {
|
||||||
|
Some(T::parse(self.prop(key)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(&self) -> Result<Entity<'a>, VdfError> {
|
pub fn parse(&self) -> Result<Entity<'a>, VdfError> {
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,6 @@ pub enum InvalidNeighbourError {
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum EntityParseError {
|
pub enum EntityParseError {
|
||||||
#[error("no such property: {0}")]
|
|
||||||
NoSuchProperty(&'static str),
|
|
||||||
#[error("wrong number of elements")]
|
#[error("wrong number of elements")]
|
||||||
ElementCount,
|
ElementCount,
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue