opendrive 0.1.0+1.7.0

OpenDRIVE parser and writer for Rust
Documentation
use std::borrow::Cow;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "fuzzing", derive(arbitrary::Arbitrary))]
pub struct LaneValidity {
    /// Minimum ID of the lanes for which the object is valid
    pub from_lane: i64,
    /// Maximum ID of the lanes for which the object is valid
    pub to_lane: i64,
}

impl LaneValidity {
    pub fn visit_attributes(
        &self,
        visitor: impl for<'b> FnOnce(
            Cow<'b, [xml::attribute::Attribute<'b>]>,
        ) -> xml::writer::Result<()>,
    ) -> xml::writer::Result<()> {
        visit_attributes!(
            visitor,
            "fromLane" => &self.from_lane.to_string(),
            "toLane" => &self.to_lane.to_string(),
        )
    }

    pub fn visit_children(
        &self,
        mut visitor: impl FnMut(xml::writer::XmlEvent) -> xml::writer::Result<()>,
    ) -> xml::writer::Result<()> {
        visit_children!(visitor);
        Ok(())
    }
}

impl<'a, I> TryFrom<crate::parser::ReadContext<'a, I>> for LaneValidity
where
    I: Iterator<Item = xml::reader::Result<xml::reader::XmlEvent>>,
{
    type Error = Box<crate::parser::Error>;

    fn try_from(mut read: crate::parser::ReadContext<'a, I>) -> Result<Self, Self::Error> {
        read.expecting_no_child_elements_for(Self {
            from_lane: read.attribute("fromLane")?,
            to_lane: read.attribute("toLane")?,
        })
    }
}