Skip to main content

sl_types/
pathfinding.rs

1//! Pathfinding related types
2
3#[cfg(feature = "chumsky")]
4use chumsky::Parser;
5
6/// Pathfinding types
7///
8/// see <https://wiki.secondlife.com/wiki/Category:LSL_Pathfinding_Types>
9#[derive(Debug, Clone, Hash, PartialEq, Eq, strum::FromRepr, strum::EnumIs)]
10#[repr(i8)]
11#[expect(
12    clippy::module_name_repetitions,
13    reason = "the type is used outside this module"
14)]
15pub enum PathfindingType {
16    /// Attachments, Linden trees & grass
17    Other = -1,
18    /// Movable obstacles, movable phantoms, physical, and volumedetect objects
19    LegacyLinkset = 0,
20    /// Avatars
21    Avatar = 1,
22    /// Pathfinding characters
23    Character = 2,
24    /// Walkable objects
25    Walkable = 3,
26    /// Static obstacles
27    StaticObstacle = 4,
28    /// Material volumes
29    MaterialVolume = 5,
30    /// Exclusion volumes
31    ExclusionVolume = 6,
32}
33
34/// parse a signed integer as a pathfinding type based on the C/LSL constant
35/// values
36///
37/// # Errors
38///
39/// returns an error if the string could not be parsed
40#[cfg(feature = "chumsky")]
41#[must_use]
42pub fn int_as_pathfinding_type_parser<'src>()
43-> impl Parser<'src, &'src str, PathfindingType, chumsky::extra::Err<chumsky::error::Rich<'src, char>>>
44{
45    crate::utils::i8_parser().try_map(|repr, span| {
46        crate::pathfinding::PathfindingType::from_repr(repr).ok_or_else(|| {
47            chumsky::error::Rich::custom(
48                span,
49                "Could not convert parsed pathfinding type i8 into PathfindingType enum",
50            )
51        })
52    })
53}