-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathroute.rs
41 lines (38 loc) · 1.26 KB
/
route.rs
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
use std::collections::HashMap;
use tracing::debug;
use super::new_ref_fix_delete_pair;
use super::Fix;
use crate::schema::InfraError;
use crate::schema::InfraErrorType;
use editoast_schemas::infra::Route;
use editoast_schemas::primitives::OSRDIdentified as _;
use editoast_schemas::primitives::OSRDObject as _;
use editoast_schemas::primitives::ObjectRef;
use editoast_schemas::primitives::ObjectType;
pub fn fix_route(
route: &Route,
errors: impl Iterator<Item = InfraError>,
) -> HashMap<ObjectRef, Fix> {
errors
.filter_map(|infra_error| match infra_error.get_sub_type() {
InfraErrorType::InvalidReference { reference }
if matches!(
reference.obj_type,
ObjectType::BufferStop | ObjectType::Detector
) =>
{
if reference.obj_id.eq(route.entry_point.get_id())
|| reference.obj_id.eq(route.exit_point.get_id())
{
Some(new_ref_fix_delete_pair(route))
} else {
None
}
}
_ => {
debug!("error not (yet) fixable for '{}'", infra_error.get_type());
None
}
})
.collect()
}