Skip to main content

maliput_sys/api/objects/
mod.rs

1// BSD 3-Clause License
2//
3// Copyright (c) 2026, Woven by Toyota.
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are met:
8//
9// * Redistributions of source code must retain the above copyright notice, this
10//   list of conditions and the following disclaimer.
11//
12// * Redistributions in binary form must reproduce the above copyright notice,
13//   this list of conditions and the following disclaimer in the documentation
14//   and/or other materials provided with the distribution.
15//
16// * Neither the name of the copyright holder nor the names of its
17//   contributors may be used to endorse or promote products derived from
18//   this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#[cxx::bridge(namespace = "maliput::api::objects")]
32#[allow(clippy::needless_lifetimes)] // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/5787
33pub mod ffi {
34    /// Shared struct for `RoadObject` pointers.
35    /// This is needed because `*const` can't be used directly in the CxxVector collection.
36    struct ConstRoadObjectPtr {
37        pub road_object: *const RoadObject,
38    }
39    /// Shared struct for `Outline` pointers.
40    /// This is needed because `*const` can't be used directly in the CxxVector collection.
41    struct ConstOutlinePtr {
42        pub outline: *const Outline,
43    }
44    /// Shared struct for `RoadMarking` pointers.
45    /// This is needed because `*const` can't be used directly in the CxxVector collection.
46    struct ConstRoadMarkingPtr {
47        pub road_marking: *const RoadMarking,
48    }
49    /// Shared struct for an optional `RoadMarkingValue`.
50    /// `value` and `unit` are meaningful only when `has_value` is true.
51    struct RoadMarkingValueData {
52        pub has_value: bool,
53        pub value: f64,
54        pub unit: RoadMarkingValueUnit,
55    }
56    /// Shared struct for outline corner data.
57    /// This is a flat representation of `OutlineCorner` to avoid a new opaque CXX type.
58    /// `height` is 0.0 when `has_height` is false.
59    struct OutlineCornerData {
60        pub x: f64,
61        pub y: f64,
62        pub z: f64,
63        pub has_height: bool,
64        pub height: f64,
65    }
66    /// Shared struct for pairs in a properties map.
67    /// This is needed because maps can't be bound directly.
68    struct StringPair {
69        pub key: String,
70        pub value: String,
71    }
72    /// Shared struct for a `ContinuousObject` sample.
73    /// This is a flat representation to avoid a new opaque CXX type.
74    struct ContinuousObjectData {
75        pub width: f64,
76        pub height: f64,
77        pub x: f64,
78        pub y: f64,
79        pub z: f64,
80    }
81
82    /// Shared enum representing different types of road objects.
83    /// This is needed to access the enum variant from Rust API since the C++ enum has an opaque implementation.
84    /// The order of these variants must match with the order of the enum class defined in maliput C++ API.
85    #[repr(i32)]
86    enum RoadObjectType {
87        kUnknown = 0,
88        kBarrier,
89        kGuardWall,
90        kGuardRail,
91        kBuilding,
92        kGantry,
93        kObstacle,
94        kPole,
95        kTrafficIsland,
96        kTree,
97        kVegetation,
98        kPylon,
99        kDelineator,
100        kBikeStatic,
101        kBusStatic,
102        kCarStatic,
103        kMotorbikeStatic,
104        kPatch,
105        kPedestrianStatic,
106        kRailing,
107        kRoadSurface,
108        kSoundBarrier,
109        kStreetLamp,
110        kTrailerStatic,
111        kTrainStatic,
112        kTramStatic,
113        kVanStatic,
114        kWind,
115    }
116
117    /// Shared enum representing the unit of a `RoadMarkingValue`.
118    /// The order of these variants must match with the order of the enum class defined in maliput C++ API.
119    #[repr(i32)]
120    enum RoadMarkingValueUnit {
121        kMetersPerSecond = 0,
122        kKilometersPerHour,
123        kMilesPerHour,
124    }
125
126    unsafe extern "C++" {
127        include!("api/objects/objects.h");
128        include!("cxx_utils/error_handling.h");
129
130        // Forward declarations from parent namespaces.
131        #[namespace = "maliput::api"]
132        type InertialPosition = crate::api::ffi::InertialPosition;
133        #[namespace = "maliput::api"]
134        type Rotation = crate::api::ffi::Rotation;
135        #[namespace = "maliput::api::rules"]
136        type TrafficControlDeviceType = crate::api::rules::ffi::TrafficControlDeviceType;
137        #[namespace = "maliput::math"]
138        type Vector3 = crate::math::ffi::Vector3;
139        #[namespace = "maliput::math"]
140        type BoundingBox = crate::math::ffi::BoundingBox;
141        // StringWrapper is reused from the rules bridge to avoid duplication.
142        #[namespace = "maliput::api::rules"]
143        type StringWrapper = crate::api::rules::ffi::StringWrapper;
144
145        // RoadObjectType opaque type - this is needed to prevent CXX from redefining the enum (it'll use a `using` alias instead).
146        type RoadObjectType;
147
148        // RoadObjectBook opaque type and bindings.
149        type RoadObjectBook;
150        fn RoadObjectBook_RoadObjects(book: &RoadObjectBook) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
151        fn RoadObjectBook_GetRoadObject(book: &RoadObjectBook, id: &String) -> *const RoadObject;
152        fn RoadObjectBook_FindByType(
153            book: &RoadObjectBook,
154            obj_type: RoadObjectType,
155        ) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
156        fn RoadObjectBook_FindByLane(
157            book: &RoadObjectBook,
158            lane_id: &String,
159        ) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
160        fn RoadObjectBook_FindInRadius(
161            book: &RoadObjectBook,
162            x: f64,
163            y: f64,
164            z: f64,
165            radius: f64,
166        ) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
167
168        // RoadObject opaque type and bindings.
169        type RoadObject;
170        fn RoadObject_id(obj: &RoadObject) -> String;
171        fn RoadObject_name(obj: &RoadObject) -> UniquePtr<StringWrapper>;
172        // This method could be bound as `fn type(self: &RoadObject) -> RoadObjectType` but it
173        // causes a conflict with the `type` keyword in Rust.
174        fn RoadObject_object_type(obj: &RoadObject) -> RoadObjectType;
175        fn RoadObject_subtype(obj: &RoadObject) -> UniquePtr<StringWrapper>;
176        fn RoadObject_position_inertial(obj: &RoadObject) -> UniquePtr<InertialPosition>;
177        fn RoadObject_position_has_lane_position(obj: &RoadObject) -> bool;
178        fn RoadObject_position_lane_id(obj: &RoadObject) -> String;
179        fn RoadObject_position_lane_s(obj: &RoadObject) -> f64;
180        fn RoadObject_position_lane_r(obj: &RoadObject) -> f64;
181        fn RoadObject_position_lane_h(obj: &RoadObject) -> f64;
182        fn RoadObject_orientation(obj: &RoadObject) -> UniquePtr<Rotation>;
183        fn RoadObject_bounding_box(obj: &RoadObject) -> UniquePtr<BoundingBox>;
184        fn is_dynamic(self: &RoadObject) -> bool;
185        fn is_movable(self: &RoadObject) -> bool;
186        fn RoadObject_related_lanes(obj: &RoadObject) -> Vec<String>;
187        fn num_outlines(self: &RoadObject) -> i32;
188        fn RoadObject_outlines(obj: &RoadObject) -> UniquePtr<CxxVector<ConstOutlinePtr>>;
189        fn RoadObject_properties(obj: &RoadObject) -> Vec<StringPair>;
190        fn RoadObject_continuous_properties(obj: &RoadObject) -> Vec<ContinuousObjectData>;
191
192        // Outline opaque type and bindings.
193        type Outline;
194        fn Outline_id(outline: &Outline) -> String;
195        fn Outline_is_closed(outline: &Outline) -> bool;
196        fn Outline_num_corners(outline: &Outline) -> i32;
197        fn Outline_corners(outline: &Outline) -> Vec<OutlineCornerData>;
198
199        // RoadMarkingValueUnit opaque type - same reason as RoadMarkingType.
200        type RoadMarkingValueUnit;
201
202        // RoadMarkingBook opaque type and bindings.
203        type RoadMarkingBook;
204        fn RoadMarkingBook_RoadMarkings(book: &RoadMarkingBook) -> UniquePtr<CxxVector<ConstRoadMarkingPtr>>;
205        fn RoadMarkingBook_GetRoadMarking(book: &RoadMarkingBook, id: &String) -> *const RoadMarking;
206        fn RoadMarkingBook_FindByLane(
207            book: &RoadMarkingBook,
208            lane_id: &String,
209        ) -> UniquePtr<CxxVector<ConstRoadMarkingPtr>>;
210        fn RoadMarkingBook_FindByType(
211            book: &RoadMarkingBook,
212            marking_type: TrafficControlDeviceType,
213        ) -> UniquePtr<CxxVector<ConstRoadMarkingPtr>>;
214
215        // RoadMarking opaque type and bindings.
216        type RoadMarking;
217        fn RoadMarking_id(marking: &RoadMarking) -> String;
218        fn RoadMarking_name(marking: &RoadMarking) -> UniquePtr<StringWrapper>;
219        // `type` is a reserved Rust keyword, so we expose it as a free function.
220        fn RoadMarking_marking_type(marking: &RoadMarking) -> TrafficControlDeviceType;
221        fn RoadMarking_position_inertial(marking: &RoadMarking) -> UniquePtr<InertialPosition>;
222        fn RoadMarking_position_has_lane_position(marking: &RoadMarking) -> bool;
223        fn RoadMarking_position_lane_id(marking: &RoadMarking) -> String;
224        fn RoadMarking_position_lane_s(marking: &RoadMarking) -> f64;
225        fn RoadMarking_position_lane_r(marking: &RoadMarking) -> f64;
226        fn RoadMarking_position_lane_h(marking: &RoadMarking) -> f64;
227        fn RoadMarking_orientation(marking: &RoadMarking) -> UniquePtr<Rotation>;
228        fn RoadMarking_bounding_box(marking: &RoadMarking) -> UniquePtr<BoundingBox>;
229        fn RoadMarking_related_lanes(marking: &RoadMarking) -> Vec<String>;
230        fn num_outlines(self: &RoadMarking) -> i32;
231        fn RoadMarking_outlines(marking: &RoadMarking) -> UniquePtr<CxxVector<ConstOutlinePtr>>;
232        fn RoadMarking_value(marking: &RoadMarking) -> RoadMarkingValueData;
233    }
234}