maliput-sys 0.23.0

FFI Rust bindings for maliput
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
// BSD 3-Clause License
//
// Copyright (c) 2024, Woven by Toyota.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
//   contributors may be used to endorse or promote products derived from
//   this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#pragma once

#include <memory>
#include <sstream>
#include <vector>

#include <maliput/api/branch_point.h>
#include <maliput/api/intersection.h>
#include <maliput/api/intersection_book.h>
#include <maliput/api/junction.h>
#include <maliput/api/lane.h>
#include <maliput/api/lane_boundary.h>
#include <maliput/api/lane_data.h>
#include <maliput/api/lane_marking.h>
#include <maliput/api/road_network.h>
#include <maliput/api/road_geometry.h>
#include <maliput/api/regions.h>
#include <maliput/api/segment.h>

#include <rust/cxx.h>

// Include the rules module header to get shared struct definitions (NextPhase, DiscreteValueRuleState, etc.)
// that are re-exported by this module.
#include "maliput-sys/src/api/rules/mod.rs.h"

#include "maliput-sys/src/api/mod.rs.h"

namespace maliput {
namespace api {

struct ConstLanePtr;
struct MutIntersectionPtr;

/// Gets the `RoadNetowrk`s read-only `IntersectionBook`.
const maliput::api::IntersectionBook* RoadNetwork_intersection_book(const RoadNetwork& road_network) {
    return const_cast<RoadNetwork&>(road_network).intersection_book();
}

/// Gets the `RoadNetowrk`s read-only `PhaseProvider`.
const maliput::api::rules::PhaseProvider* RoadNetwork_phase_provider(const RoadNetwork& road_network) {
    maliput::api::RoadNetwork* rn = const_cast<RoadNetwork*>(&road_network);
    maliput::api::rules::PhaseProvider* phase_provider = rn->phase_provider();
    return phase_provider;
}

/// Gets the `RoadNetowrk`s read-only `DiscreteValueRuleStateProvider`.
const maliput::api::rules::DiscreteValueRuleStateProvider* RoadNetwork_discrete_value_rule_state_provider(const RoadNetwork& road_network) {
    maliput::api::RoadNetwork* rn = const_cast<RoadNetwork*>(&road_network);
    maliput::api::rules::DiscreteValueRuleStateProvider* discrete_value_rule_state_provider = rn->discrete_value_rule_state_provider();
    return discrete_value_rule_state_provider;
}

/// Gets the `RoadNetowrk`s read-only `RangeValueRuleStateProvider`.
const maliput::api::rules::RangeValueRuleStateProvider* RoadNetwork_range_value_rule_state_provider(const RoadNetwork& road_network) {
    maliput::api::RoadNetwork* rn = const_cast<RoadNetwork*>(&road_network);
    maliput::api::rules::RangeValueRuleStateProvider* range_value_rule_state_provider = rn->range_value_rule_state_provider();
    return range_value_rule_state_provider;
}

/// Creates a new maliput::api::LanePosition.
/// Forwads to maliput::api::LanePosition(double s, double r, double h) constructor.
std::unique_ptr<LanePosition> LanePosition_new(rust::f64 s, rust::f64 r, rust::f64 h) {
  return std::make_unique<LanePosition>(s, r, h);
}

/// Creates a new maliput::api::LanePosition.
/// Forwads to maliput::api::LanePosition(double s, double r, double h) constructor.
rust::String LanePosition_to_str(const LanePosition& lane_pos) {
  std::stringstream ss;
  ss << lane_pos;
  return {ss.str()};
}

/// Creates a new maliput::api::InertialPosition.
/// Forwads to maliput::api::InertialPosition(double x, double y, double z) constructor.
std::unique_ptr<InertialPosition> InertialPosition_new(rust::f64 x, rust::f64 y, rust::f64 z) {
  return std::make_unique<InertialPosition>(x, y, z);
}

rust::String InertialPosition_to_str(const InertialPosition& inertial_pos) {
  std::stringstream ss;
  ss << inertial_pos;
  return {ss.str()};
}

std::unique_ptr<InertialPosition> InertialPosition_operator_sum(const InertialPosition& lhs, const InertialPosition& rhs) {
  return std::make_unique<InertialPosition>(lhs + rhs);
}

std::unique_ptr<InertialPosition> InertialPosition_operator_sub(const InertialPosition& lhs, const InertialPosition& rhs) {
  return std::make_unique<InertialPosition>(lhs - rhs);
}

std::unique_ptr<InertialPosition> InertialPosition_operator_mul_scalar(const InertialPosition& lhs, rust::f64 scalar) {
  return std::make_unique<InertialPosition>(lhs * scalar);
}

bool InertialPosition_operator_eq(const InertialPosition& lhs, const InertialPosition& rhs) {
  return lhs == rhs;
}

rust::String Segment_id(const Segment& segment) {
  return segment.id().string();
}

rust::String Junction_id(const Junction& junction) {
  return junction.id().string();
}

rust::String Lane_id(const Lane& lane) {
  return lane.id().string();
}

std::unique_ptr<Rotation> Lane_GetOrientation(const Lane& lane, const LanePosition& lane_position) {
  return std::make_unique<Rotation>(lane.GetOrientation(lane_position));
}

std::unique_ptr<InertialPosition> Lane_ToInertialPosition(const Lane& lane, const LanePosition& lane_position) {
  return std::make_unique<InertialPosition>(lane.ToInertialPosition(lane_position));
}

std::unique_ptr<RBounds>Lane_lane_bounds(const Lane& lane, rust::f64 s) {
  return std::make_unique<RBounds>(lane.lane_bounds(s));
}

std::unique_ptr<RBounds>Lane_segment_bounds(const Lane& lane, rust::f64 s) {
  return std::make_unique<RBounds>(lane.segment_bounds(s));
}

std::unique_ptr<HBounds>Lane_elevation_bounds(const Lane& lane, rust::f64 s, rust::f64 r) {
  return std::make_unique<HBounds>(lane.elevation_bounds(s, r));
}

std::unique_ptr<LanePositionResult> Lane_ToLanePosition(const Lane& lane, const InertialPosition& inertial_pos) {
  return std::make_unique<LanePositionResult>(lane.ToLanePosition(inertial_pos));
}

std::unique_ptr<LanePositionResult> Lane_ToSegmentPosition(const Lane& lane, const InertialPosition& inertial_pos) {
  return std::make_unique<LanePositionResult>(lane.ToSegmentPosition(inertial_pos));
}

const BranchPoint* Lane_GetBranchPoint(const Lane& lane, bool start) {
  return lane.GetBranchPoint(start ? LaneEnd::kStart : LaneEnd::kFinish);
}

const LaneEndSet* Lane_GetConfluentBranches(const Lane& lane, bool start) {
  return lane.GetConfluentBranches(start ? LaneEnd::kStart : LaneEnd::kFinish);
}

const LaneEndSet* Lane_GetOngoingBranches(const Lane& lane, bool start) {
  return lane.GetOngoingBranches(start ? LaneEnd::kStart : LaneEnd::kFinish);
}

std::unique_ptr<LaneEnd> Lane_GetDefaultBranch(const Lane& lane, bool start) {
  const auto default_branch = lane.GetDefaultBranch(start ? LaneEnd::kStart : LaneEnd::kFinish);
  return default_branch ? std::make_unique<LaneEnd>(*default_branch) : nullptr;
}

std::unique_ptr<LanePosition> Lane_EvalMotionDerivatives(const Lane& lane, const LanePosition& lane_position, rust::f64 sigma_v, rust::f64 rho_v, rust::f64 eta_v) {
  return std::make_unique<LanePosition>(lane.EvalMotionDerivatives(lane_position, IsoLaneVelocity{sigma_v, rho_v, eta_v}));
}

LaneType Lane_type(const Lane& lane) {
  return lane.type();
}

std::unique_ptr<RoadPosition> RoadPosition_new(const Lane* lane, const LanePosition& pos) {
  return std::make_unique<RoadPosition>(lane, pos);
}

std::unique_ptr<InertialPosition> RoadPosition_ToInertialPosition(const RoadPosition& road_pos) {
  return std::make_unique<InertialPosition>(road_pos.ToInertialPosition());
}

const Lane* RoadPosition_lane(const RoadPosition& road_pos) {
  return road_pos.lane;
}

std::unique_ptr<LanePosition> RoadPosition_pos(const RoadPosition& road_pos) {
  return std::make_unique<LanePosition>(road_pos.pos);
}

std::unique_ptr<RoadPosition> RoadPositionResult_road_position(const RoadPositionResult& road_pos_res) {
  return std::make_unique<RoadPosition>(road_pos_res.road_position);
}

std::unique_ptr<InertialPosition> RoadPositionResult_nearest_position (const RoadPositionResult& road_pos_res) {
  return std::make_unique<InertialPosition>(road_pos_res.nearest_position);
}

double RoadPositionResult_distance(const RoadPositionResult& road_pos_res) {
  return road_pos_res.distance;
}

std::unique_ptr<LanePosition> LanePositionResult_road_position(const LanePositionResult& lane_pos_res) {
  return std::make_unique<LanePosition>(lane_pos_res.lane_position);
}

std::unique_ptr<InertialPosition> LanePositionResult_nearest_position (const LanePositionResult& lane_pos_res) {
  return std::make_unique<InertialPosition>(lane_pos_res.nearest_position);
}

double LanePositionResult_distance(const LanePositionResult& lane_pos_res) {
  return lane_pos_res.distance;
}

rust::String RoadGeometry_id(const RoadGeometry& road_geometry) {
  return road_geometry.id().string();
}

std::unique_ptr<RoadPositionResult> RoadGeometry_ToRoadPosition(const RoadGeometry& road_geometry, const InertialPosition& inertial_pos) {
  return std::make_unique<RoadPositionResult>(road_geometry.ToRoadPosition(inertial_pos));
}

std::unique_ptr<std::vector<RoadPositionResult>> RoadGeometry_FindRoadPositions(const RoadGeometry& road_geometry, const InertialPosition& inertial_pos, double radius) {
  return std::make_unique<std::vector<RoadPositionResult>>(road_geometry.FindRoadPositions(inertial_pos, radius));
}

std::unique_ptr<std::vector<RoadPositionResult>> RoadGeometry_FindSurfaceRoadPositionsAtXY(const RoadGeometry& road_geometry, double x, double y, double radius) {
  return std::make_unique<std::vector<RoadPositionResult>>(road_geometry.FindSurfaceRoadPositionsAtXY(x, y, radius));
}

ConstLanePtr RoadGeometry_GetLane(const RoadGeometry& road_geometry, const rust::String& lane_id) {
  return {road_geometry.ById().GetLane(LaneId{std::string(lane_id)})};
}

std::unique_ptr<std::vector<ConstLanePtr>> RoadGeometry_GetLanes(const RoadGeometry& road_geometry) {
  std::vector<ConstLanePtr> lanes;
  const auto lanes_cpp = road_geometry.ById().GetLanes();
  lanes.reserve(lanes_cpp.size());
  for (const auto& lane : road_geometry.ById().GetLanes()) {
    lanes.push_back(ConstLanePtr{lane.second});
  }
  return std::make_unique<std::vector<ConstLanePtr>>(std::move(lanes));
}

const BranchPoint* RoadGeometry_GetBranchPoint(const RoadGeometry& road_geometry, const rust::String& branch_point_id) {
  return road_geometry.ById().GetBranchPoint(BranchPointId{std::string(branch_point_id)});
}

const Segment* RoadGeometry_GetSegment(const RoadGeometry& road_geometry, const rust::String& segment_id) {
  return road_geometry.ById().GetSegment(SegmentId{std::string(segment_id)});
}

const Junction* RoadGeometry_GetJunction(const RoadGeometry& road_geometry, const rust::String& junction_id) {
  return road_geometry.ById().GetJunction(JunctionId{std::string(junction_id)});
}

rust::String RoadGeometry_BackendCustomCommand(const RoadGeometry& road_geometry, const rust::String& command) {
  return road_geometry.BackendCustomCommand(std::string(command));
}

rust::String RoadGeometry_GeoReferenceInfo(const RoadGeometry& road_geometry) {
  return road_geometry.GeoReferenceInfo();
}

const LaneBoundary* RoadGeometry_GetLaneBoundary(const RoadGeometry& road_geometry, const rust::String& boundary_id) {
  return road_geometry.ById().GetLaneBoundary(LaneBoundary::Id{std::string(boundary_id)});
}

std::unique_ptr<Rotation> Rotation_new() {
  return std::make_unique<Rotation>();
}

std::unique_ptr<Rotation> Rotation_from_quat(const maliput::math::Quaternion& q) {
  return std::make_unique<Rotation>(Rotation::FromQuat(q));
}

std::unique_ptr<Rotation> Rotation_from_rpy(const maliput::math::RollPitchYaw& rpy) {
  return std::make_unique<Rotation>(Rotation::FromRpy(rpy.vector()));
}

void Rotation_set_quat(Rotation& rotation, const maliput::math::Quaternion& q) {
  rotation.set_quat(q);
}

std::unique_ptr<maliput::math::RollPitchYaw> Rotation_rpy(const Rotation& rotation) {
  return std::make_unique<maliput::math::RollPitchYaw>(rotation.rpy());
}

std::unique_ptr<maliput::math::Matrix3> Rotation_matrix(const Rotation& rotation) {
  return std::make_unique<maliput::math::Matrix3>(rotation.matrix());
}

std::unique_ptr<InertialPosition> Rotation_Apply(const Rotation& rotation, const InertialPosition& inertial_pos) {
  return std::make_unique<InertialPosition>(rotation.Apply(inertial_pos));
}

std::unique_ptr<Rotation> Rotation_Reverse(const Rotation& rotation) {
  return std::make_unique<Rotation>(rotation.Reverse());
}

std::unique_ptr<SRange> SRange_new(rust::f64 start, rust::f64 end) {
  return std::make_unique<SRange>(start, end);
}

std::unique_ptr<SRange> SRange_GetIntersection(const SRange& s_range, const SRange& other_s_range, rust::f64 tolerance) {
  const auto intersection = s_range.GetIntersection(other_s_range, tolerance);
  if (intersection) {
    return std::make_unique<SRange>(*intersection);
  }
  return nullptr;
}

std::unique_ptr<LaneSRange> LaneSRange_new(const rust::String& lane_id, const SRange& s_range) {
  return std::make_unique<LaneSRange>(LaneId{std::string(lane_id)}, s_range);
}

rust::String LaneSRange_lane_id(const LaneSRange& lane_s_range) {
  return lane_s_range.lane_id().string();
}

std::unique_ptr<SRange> LaneSRange_s_range(const LaneSRange& lane_s_range) {
  return std::make_unique<SRange>(lane_s_range.s_range());
}

std::unique_ptr<LaneSRange> LaneSRange_GetIntersection(const LaneSRange& lane_s_range, const LaneSRange& other_lane_s_range, rust::f64 tolerance) {
  const auto intersection = lane_s_range.GetIntersection(other_lane_s_range, tolerance);
  if (intersection) {
    return std::make_unique<LaneSRange>(*intersection);
  }
  return nullptr;
}

std::unique_ptr<LaneSRoute> LaneSRoute_new(const std::vector<ConstLaneSRangeRef>& lane_s_ranges) {
  std::vector<LaneSRange> lane_s_ranges_cpp;
  lane_s_ranges_cpp.reserve(lane_s_ranges.size());
  for (const auto& lane_s_range : lane_s_ranges) {
    lane_s_ranges_cpp.push_back(LaneSRange{lane_s_range.lane_s_range.lane_id(), lane_s_range.lane_s_range.s_range()});
  }
  return std::make_unique<LaneSRoute>(lane_s_ranges_cpp);
}

std::unique_ptr<LaneEnd> LaneEnd_new(const Lane* lane, bool start) {
  return std::make_unique<LaneEnd>(lane, start ? LaneEnd::kStart : LaneEnd::kFinish);
}

const Lane* LaneEnd_lane(const LaneEnd& lane_end) {
  return lane_end.lane;
}

bool LaneEnd_is_start(const LaneEnd& lane_end) {
  return lane_end.end == LaneEnd::kStart;
}

rust::String BranchPoint_id(const BranchPoint& branch_point) {
  return branch_point.id().string();
}

std::unique_ptr<LaneEnd> BranchPoint_GetDefaultBranch(const BranchPoint& branch_point, const LaneEnd& end) {
  const auto default_branch = branch_point.GetDefaultBranch(end);
  return default_branch ? std::make_unique<LaneEnd>(*default_branch) : nullptr;
}

rust::String Intersection_id(const Intersection& intersection) {
  return intersection.id().string();
}

std::unique_ptr<rules::StateProviderResult<rules::Phase::Id>> Intersection_Phase(const Intersection& intersection) {
  const auto phase_state_provider_query = intersection.Phase();
  return phase_state_provider_query ? std::make_unique<rules::StateProviderResult<rules::Phase::Id>>(*phase_state_provider_query) : nullptr;
}

rust::String Intersection_ring_id(const Intersection& intersection) {
  return intersection.ring_id().string();
}

std::unique_ptr<std::vector<rules::UniqueBulbId>> Intersection_unique_bulb_ids(const Intersection& intersection) {
  std::vector<rules::UniqueBulbId> bulb_ids;
  const auto bulb_ids_cpp = intersection.bulb_states();

  if (!bulb_ids_cpp.has_value()) {
    return nullptr;
  }

  bulb_ids.reserve(bulb_ids_cpp->size());

  for (const auto& bulb_id_pair : bulb_ids_cpp.value()) {
    bulb_ids.push_back(bulb_id_pair.first);
  }

  return std::make_unique<std::vector<rules::UniqueBulbId>>(std::move(bulb_ids));
}

std::unique_ptr<rules::BulbState> Intersection_bulb_state(const Intersection& intersection, const rules::UniqueBulbId& bulb_id) {
  const auto bulb_states_cpp = intersection.bulb_states();

  if (!bulb_states_cpp.has_value()) {
    return nullptr;
  }
  const auto it = bulb_states_cpp.value().find(bulb_id);
  if (it == bulb_states_cpp.value().end()) {
    return nullptr;
  }
  return std::make_unique<rules::BulbState>(it->second);
}

std::unique_ptr<std::vector<rules::DiscreteValueRuleState>> Intersection_DiscreteValueRuleStates(const Intersection& intersection) {
  std::vector<rules::DiscreteValueRuleState> discrete_value_rule_states;
  const auto discrete_value_rule_states_cpp = intersection.DiscreteValueRuleStates();

  if (!discrete_value_rule_states_cpp.has_value()) {
    return nullptr;
  }
  for (const auto& discrete_value_state : discrete_value_rule_states_cpp.value()) {
    rules::DiscreteValueRuleState discrete_value_rule_state{discrete_value_state.first.string(), std::make_unique<rules::DiscreteValueRuleDiscreteValue>(discrete_value_state.second)};
    discrete_value_rule_states.emplace_back(std::move(discrete_value_rule_state));
  }
  return std::make_unique<std::vector<rules::DiscreteValueRuleState>>(std::move(discrete_value_rule_states));
}

bool Intersection_IncludesTrafficLight(const Intersection& intersection, const rust::String& traffic_light_id) {
  return intersection.Includes(rules::TrafficLight::Id{std::string(traffic_light_id)});
}

bool Intersection_IncludesDiscreteValueRule(const Intersection& intersection, const rust::String& rule_id) {
  return intersection.Includes(rules::DiscreteValueRule::Id{std::string(rule_id)});
}

bool Intersection_IncludesInertialPosition(const Intersection& intersection, const InertialPosition& inertial_pos, const RoadGeometry& road_geometry) {
  return intersection.Includes(inertial_pos, &road_geometry);
}

MutIntersectionPtr IntersectionBook_GetIntersection(const IntersectionBook& intersection_book, const rust::String& intersection_id) {
  return {const_cast<IntersectionBook&>(intersection_book).GetIntersection(Intersection::Id{std::string(intersection_id)})};
}

// IntersectionBook_GetIntersections
std::unique_ptr<std::vector<MutIntersectionPtr>> IntersectionBook_GetIntersections(const IntersectionBook& intersection_book) {
  auto intersections_cpp = const_cast<IntersectionBook&>(intersection_book).GetIntersections();
  std::vector<MutIntersectionPtr> intersections;
  intersections.reserve(intersections_cpp.size());
  for (const auto& intersection : intersections_cpp) {
    intersections.push_back(MutIntersectionPtr{intersection});
  }
  return std::make_unique<std::vector<MutIntersectionPtr>>(std::move(intersections));
}

MutIntersectionPtr IntersectionBook_FindIntersectionTrafficLight(const IntersectionBook& intersection_book, const rust::String& traffic_light_id) {
  return {const_cast<IntersectionBook&>(intersection_book).FindIntersection(rules::TrafficLight::Id{std::string(traffic_light_id)})};
}

MutIntersectionPtr IntersectionBook_FindIntersectionDiscreteValueRule(const IntersectionBook& intersection_book, const rust::String& rule_id) {
  return {const_cast<IntersectionBook&>(intersection_book).FindIntersection(rules::DiscreteValueRule::Id{std::string(rule_id)})};
}

MutIntersectionPtr IntersectionBook_FindIntersectionInertialPosition(const IntersectionBook& intersection_book, const InertialPosition& inertial_pos) {
  return {const_cast<IntersectionBook&>(intersection_book).FindIntersection(inertial_pos)};
}

// @defgroup LaneMarkingLine helpers.
// @{

double LaneMarkingLine_length(const LaneMarkingLine& lane_marking_line) {
  return lane_marking_line.length;
}

double LaneMarkingLine_space(const LaneMarkingLine& lane_marking_line) {
  return lane_marking_line.space;
}

double LaneMarkingLine_width(const LaneMarkingLine& lane_marking_line) {
  return lane_marking_line.width;
}

double LaneMarkingLine_r_offset(const LaneMarkingLine& lane_marking_line) {
  return lane_marking_line.r_offset;
}

LaneMarkingColor LaneMarkingLine_color(const LaneMarkingLine& lane_marking_line) {
  return lane_marking_line.color;
}

// @}

// @defgroup LaneMarkingResult helpers.
// @{

std::unique_ptr<LaneMarking> LaneMarkingResult_marking(const LaneMarkingResult& lane_marking_result) {
  return std::make_unique<LaneMarking>(lane_marking_result.marking);
}

double LaneMarkingResult_s_start(const LaneMarkingResult& lane_marking_result) {
  return lane_marking_result.s_start;
}

double LaneMarkingResult_s_end(const LaneMarkingResult& lane_marking_result) {
  return lane_marking_result.s_end;
}

// @}

// @defgroup LaneMarking helpers.
// @{

double LaneMarking_width(const LaneMarking& lane_marking) {
  return lane_marking.width;
}

double LaneMarking_height(const LaneMarking& lane_marking) {
  return lane_marking.height;
}

rust::String LaneMarking_material(const LaneMarking& lane_marking) {
  return lane_marking.material;
}

LaneMarkingType LaneMarking_type(const LaneMarking& lane_marking) {
  return lane_marking.type;
}

LaneMarkingWeight LaneMarking_weight(const LaneMarking& lane_marking) {
  return lane_marking.weight;
}

LaneMarkingColor LaneMarking_color(const LaneMarking& lane_marking) {
  return lane_marking.color;
}

LaneChangePermission LaneMarking_lane_change(const LaneMarking& lane_marking) {
  return lane_marking.lane_change;
}

std::unique_ptr<std::vector<LaneMarkingLine>> LaneMarking_lines(const LaneMarking& lane_marking) {
  std::vector<LaneMarkingLine> lines;
  lines.reserve(lane_marking.lines.size());
  for (const auto& line : lane_marking.lines) {
    lines.push_back(line);
  }
  return std::make_unique<std::vector<LaneMarkingLine>>(std::move(lines));
}

// @}

// @defgroup LaneBoundary helpers.
// @{

rust::String LaneBoundary_id(const LaneBoundary& lane_boundary) {
  return lane_boundary.id().string();
}

std::unique_ptr<LaneMarkingResult> LaneBoundary_GetMarking(const LaneBoundary& lane_boundary, double s) {
  const auto marking = lane_boundary.GetMarking(s);
  if (!marking.has_value()) {
    return nullptr;
  }
  return std::make_unique<LaneMarkingResult>(marking.value());
}

std::unique_ptr<std::vector<LaneMarkingResult>> LaneBoundary_GetMarkings(const LaneBoundary& lane_boundary) {
  std::vector<LaneMarkingResult> markings;
  const auto markings_cpp = lane_boundary.GetMarkings();
  markings.reserve(markings_cpp.size());
  for (const auto& marking : markings_cpp) {
    markings.emplace_back(marking);
  }
  return std::make_unique<std::vector<LaneMarkingResult>>(std::move(markings));
}

std::unique_ptr<std::vector<LaneMarkingResult>> LaneBoundary_GetMarkingsByRange(const LaneBoundary& lane_boundary, double s_start, double s_end) {
  std::vector<LaneMarkingResult> markings;
  const auto markings_cpp = lane_boundary.GetMarkings(s_start, s_end);
  markings.reserve(markings_cpp.size());
  for (const auto& marking : markings_cpp) {
    markings.emplace_back(marking);
  }
  return std::make_unique<std::vector<LaneMarkingResult>>(std::move(markings));
}

// @}

} // namespace api
} // namespace maliput