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
73    /// Shared enum representing different types of road objects.
74    /// This is needed to access the enum variant from Rust API since the C++ enum has an opaque implementation.
75    /// The order of these variants must match with the order of the enum class defined in maliput C++ API.
76    #[repr(i32)]
77    enum RoadObjectType {
78        kUnknown = 0,
79        kBarrier,
80        kGuardWall,
81        kGuardRail,
82        kBuilding,
83        kGantry,
84        kObstacle,
85        kPole,
86        kTrafficIsland,
87        kTree,
88        kVegetation,
89        kPylon,
90        kDelineator,
91        kBikeStatic,
92        kBusStatic,
93        kCarStatic,
94        kMotorbikeStatic,
95        kPatch,
96        kPedestrianStatic,
97        kRailing,
98        kRoadSurface,
99        kSoundBarrier,
100        kStreetLamp,
101        kTrailerStatic,
102        kTrainStatic,
103        kTramStatic,
104        kVanStatic,
105        kWind,
106    }
107
108    /// Shared enum representing the unit of a `RoadMarkingValue`.
109    /// The order of these variants must match with the order of the enum class defined in maliput C++ API.
110    #[repr(i32)]
111    enum RoadMarkingValueUnit {
112        kMetersPerSecond = 0,
113        kKilometersPerHour,
114        kMilesPerHour,
115    }
116
117    unsafe extern "C++" {
118        include!("api/objects/objects.h");
119        include!("cxx_utils/error_handling.h");
120
121        // Forward declarations from parent namespaces.
122        #[namespace = "maliput::api"]
123        type InertialPosition = crate::api::ffi::InertialPosition;
124        #[namespace = "maliput::api"]
125        type Rotation = crate::api::ffi::Rotation;
126        #[namespace = "maliput::api::rules"]
127        type TrafficControlDeviceType = crate::api::rules::ffi::TrafficControlDeviceType;
128        #[namespace = "maliput::math"]
129        type Vector3 = crate::math::ffi::Vector3;
130        #[namespace = "maliput::math"]
131        type BoundingBox = crate::math::ffi::BoundingBox;
132        // StringWrapper is reused from the rules bridge to avoid duplication.
133        #[namespace = "maliput::api::rules"]
134        type StringWrapper = crate::api::rules::ffi::StringWrapper;
135
136        // RoadObjectType opaque type - this is needed to prevent CXX from redefining the enum (it'll use a `using` alias instead).
137        type RoadObjectType;
138
139        // RoadObjectBook opaque type and bindings.
140        type RoadObjectBook;
141        fn RoadObjectBook_RoadObjects(book: &RoadObjectBook) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
142        fn RoadObjectBook_GetRoadObject(book: &RoadObjectBook, id: &String) -> *const RoadObject;
143        fn RoadObjectBook_FindByType(
144            book: &RoadObjectBook,
145            obj_type: RoadObjectType,
146        ) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
147        fn RoadObjectBook_FindByLane(
148            book: &RoadObjectBook,
149            lane_id: &String,
150        ) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
151        fn RoadObjectBook_FindInRadius(
152            book: &RoadObjectBook,
153            x: f64,
154            y: f64,
155            z: f64,
156            radius: f64,
157        ) -> UniquePtr<CxxVector<ConstRoadObjectPtr>>;
158
159        // RoadObject opaque type and bindings.
160        type RoadObject;
161        fn RoadObject_id(obj: &RoadObject) -> String;
162        fn RoadObject_name(obj: &RoadObject) -> UniquePtr<StringWrapper>;
163        // This method could be bound as `fn type(self: &RoadObject) -> RoadObjectType` but it
164        // causes a conflict with the `type` keyword in Rust.
165        fn RoadObject_object_type(obj: &RoadObject) -> RoadObjectType;
166        fn RoadObject_subtype(obj: &RoadObject) -> UniquePtr<StringWrapper>;
167        fn RoadObject_position_inertial(obj: &RoadObject) -> UniquePtr<InertialPosition>;
168        fn RoadObject_position_has_lane_position(obj: &RoadObject) -> bool;
169        fn RoadObject_position_lane_id(obj: &RoadObject) -> String;
170        fn RoadObject_position_lane_s(obj: &RoadObject) -> f64;
171        fn RoadObject_position_lane_r(obj: &RoadObject) -> f64;
172        fn RoadObject_position_lane_h(obj: &RoadObject) -> f64;
173        fn RoadObject_orientation(obj: &RoadObject) -> UniquePtr<Rotation>;
174        fn RoadObject_bounding_box(obj: &RoadObject) -> UniquePtr<BoundingBox>;
175        fn is_dynamic(self: &RoadObject) -> bool;
176        fn is_movable(self: &RoadObject) -> bool;
177        fn RoadObject_related_lanes(obj: &RoadObject) -> Vec<String>;
178        fn num_outlines(self: &RoadObject) -> i32;
179        fn RoadObject_outlines(obj: &RoadObject) -> UniquePtr<CxxVector<ConstOutlinePtr>>;
180        fn RoadObject_properties(obj: &RoadObject) -> Vec<StringPair>;
181
182        // Outline opaque type and bindings.
183        type Outline;
184        fn Outline_id(outline: &Outline) -> String;
185        fn Outline_is_closed(outline: &Outline) -> bool;
186        fn Outline_num_corners(outline: &Outline) -> i32;
187        fn Outline_corners(outline: &Outline) -> Vec<OutlineCornerData>;
188
189        // RoadMarkingValueUnit opaque type - same reason as RoadMarkingType.
190        type RoadMarkingValueUnit;
191
192        // RoadMarkingBook opaque type and bindings.
193        type RoadMarkingBook;
194        fn RoadMarkingBook_RoadMarkings(book: &RoadMarkingBook) -> UniquePtr<CxxVector<ConstRoadMarkingPtr>>;
195        fn RoadMarkingBook_GetRoadMarking(book: &RoadMarkingBook, id: &String) -> *const RoadMarking;
196        fn RoadMarkingBook_FindByLane(
197            book: &RoadMarkingBook,
198            lane_id: &String,
199        ) -> UniquePtr<CxxVector<ConstRoadMarkingPtr>>;
200        fn RoadMarkingBook_FindByType(
201            book: &RoadMarkingBook,
202            marking_type: TrafficControlDeviceType,
203        ) -> UniquePtr<CxxVector<ConstRoadMarkingPtr>>;
204
205        // RoadMarking opaque type and bindings.
206        type RoadMarking;
207        fn RoadMarking_id(marking: &RoadMarking) -> String;
208        fn RoadMarking_name(marking: &RoadMarking) -> UniquePtr<StringWrapper>;
209        // `type` is a reserved Rust keyword, so we expose it as a free function.
210        fn RoadMarking_marking_type(marking: &RoadMarking) -> TrafficControlDeviceType;
211        fn RoadMarking_position_inertial(marking: &RoadMarking) -> UniquePtr<InertialPosition>;
212        fn RoadMarking_position_has_lane_position(marking: &RoadMarking) -> bool;
213        fn RoadMarking_position_lane_id(marking: &RoadMarking) -> String;
214        fn RoadMarking_position_lane_s(marking: &RoadMarking) -> f64;
215        fn RoadMarking_position_lane_r(marking: &RoadMarking) -> f64;
216        fn RoadMarking_position_lane_h(marking: &RoadMarking) -> f64;
217        fn RoadMarking_orientation(marking: &RoadMarking) -> UniquePtr<Rotation>;
218        fn RoadMarking_bounding_box(marking: &RoadMarking) -> UniquePtr<BoundingBox>;
219        fn RoadMarking_related_lanes(marking: &RoadMarking) -> Vec<String>;
220        fn num_outlines(self: &RoadMarking) -> i32;
221        fn RoadMarking_outlines(marking: &RoadMarking) -> UniquePtr<CxxVector<ConstOutlinePtr>>;
222        fn RoadMarking_value(marking: &RoadMarking) -> RoadMarkingValueData;
223    }
224}