Skip to content

Commit

Permalink
RoadGeometryt::get_lane returns an Option. (#97)
Browse files Browse the repository at this point in the history
Signed-off-by: Franco Cipollone <[email protected]>
  • Loading branch information
francocipollone authored May 14, 2024
1 parent 43d7c3e commit 9b5556a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
22 changes: 13 additions & 9 deletions maliput/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,19 @@ impl<'a> RoadGeometry<'a> {
}
}
/// Get the lane matching given `lane_id`.
pub fn get_lane(&self, lane_id: &String) -> Lane {
unsafe {
Lane {
lane: maliput_sys::api::ffi::RoadGeometry_GetLane(self.rg, lane_id)
.lane
.as_ref()
.expect(""),
}
}
/// ### Arguments
/// * `lane_id` - The id of the lane.
/// ### Return
/// The lane with the given id.
/// If no lane is found with the given id, return None.
pub fn get_lane(&self, lane_id: &String) -> Option<Lane> {
let lane = maliput_sys::api::ffi::RoadGeometry_GetLane(self.rg, lane_id);
if lane.lane.is_null() {
return None;
}
Some(Lane {
lane: unsafe { lane.lane.as_ref().expect("") },
})
}
/// Get all lanes of the `RoadGeometry`.
/// Returns a vector of `Lane`.
Expand Down
4 changes: 2 additions & 2 deletions maliput/tests/lane_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ fn lane_end_api_test() {
let road_geometry = road_network.road_geometry();

let lane_id = String::from("0_0_1");
let lane_end_start = maliput::api::LaneEnd::Start(road_geometry.get_lane(&lane_id));
let lane_end_end = maliput::api::LaneEnd::Finish(road_geometry.get_lane(&lane_id));
let lane_end_start = maliput::api::LaneEnd::Start(road_geometry.get_lane(&lane_id).unwrap());
let lane_end_end = maliput::api::LaneEnd::Finish(road_geometry.get_lane(&lane_id).unwrap());
assert_eq!(&lane_end_start, &lane_end_start);
assert_ne!(&lane_end_start, &lane_end_end);
match lane_end_start {
Expand Down
3 changes: 2 additions & 1 deletion maliput/tests/road_geometry_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ fn by_index() {
let road_geometry = road_network.road_geometry();
let lane_id = String::from("0_0_1");
let lane = road_geometry.get_lane(&lane_id);
assert_eq!(lane.id(), "0_0_1");
assert!(lane.is_some());
assert_eq!(lane.unwrap().id(), "0_0_1");

let lanes = road_geometry.get_lanes();
assert_eq!(lanes.len(), 12);
Expand Down

0 comments on commit 9b5556a

Please sign in to comment.