1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-03 10:44:07 +02:00

remove EntityParseError::NoSuchProperty

Optional semantics should not be folded into the error type.
This commit is contained in:
Quaternions 2025-02-14 09:18:07 -08:00
commit bfc70d63cd
2 changed files with 6 additions and 6 deletions

View file

@ -102,14 +102,16 @@ impl<'a> RawEntity<'a> {
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()
.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> {
T::parse(self.prop(key)?)
pub fn prop_parse<T: EntityProp<'a>>(
&self,
key: &'static str,
) -> Option<Result<T, EntityParseError>> {
Some(T::parse(self.prop(key)?))
}
pub fn parse(&self) -> Result<Entity<'a>, VdfError> {

View file

@ -124,8 +124,6 @@ pub enum InvalidNeighbourError {
#[derive(Debug, Error)]
pub enum EntityParseError {
#[error("no such property: {0}")]
NoSuchProperty(&'static str),
#[error("wrong number of elements")]
ElementCount,
#[error(transparent)]