Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove 'mutable-model' feature #883

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Hove <team.coretools@kisio.com>", "Guillaume Pinot <texitoi@texitoi.eu>"]
name = "transit_model"
version = "0.53.0"
version = "0.54.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/hove-io/transit_model"
Expand Down Expand Up @@ -34,8 +34,6 @@ members = [
xmllint = ["proj"]
gtfs = []
parser = []
# Experimental feature, use at your own risks
mutable-model = []

[dependencies]
anyhow = "1"
Expand Down
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
//! this case, take a look at the [`CONTRIBUTING.md`] for more information on
//! this feature.
//!
//! ## `mutable-model`
//! This is an experimental feature that allows you to get some abilities to
//! mutate a `Model`. It might not be completely stable at the moment so use
//! with care (or not at all!).
//!
//! ## `gtfs`
//! This is an experimental feature that exposes some gtfs functions for use
//! in external projects
Expand Down
80 changes: 0 additions & 80 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,6 @@ impl Collections {
pub struct Model {
collections: Collections,

// WARNING: Please check all methods that takes &mut self before adding a new relation (see feature 'mutable-model')
// original relations
networks_to_lines: OneToMany<Network, Line>,
commercial_modes_to_lines: OneToMany<CommercialMode, Line>,
Expand Down Expand Up @@ -1408,85 +1407,6 @@ impl Model {
self.collections
}
}
#[cfg(feature = "mutable-model")]
impl Model {
/// Add a Calendar inside the model
pub fn add_calendar(&mut self, calendar: Calendar) -> Result<Idx<Calendar>> {
self.collections
.calendars
.push(calendar)
.map_err(|e| anyhow!("{}", e))
}
/// Add a new relation between a calendar and some vehicle journeys
pub fn connect_calendar_to_vehicle_journeys(
&mut self,
calendar_idx: Idx<Calendar>,
vehicle_journey_idxs: impl IntoIterator<Item = Idx<VehicleJourney>>,
) -> Result<()> {
let calendar_id = &self.collections.calendars[calendar_idx].id;
for vehicle_journey_idx in vehicle_journey_idxs {
self.collections
.vehicle_journeys
.index_mut(vehicle_journey_idx)
.service_id = calendar_id.clone();
}
self.calendars_to_vehicle_journeys = OneToMany::new(
&self.collections.calendars,
&self.collections.vehicle_journeys,
"calendars_to_vehicle_journeys",
)?;
Ok(())
}
}

#[cfg(all(test, feature = "mutable-model"))]
mod mutable_model_tests {
use relational_types::IdxSet;
use transit_model_builder::{Calendar, VehicleJourney};

#[test]
fn test_add_calendar() {
let mut model = transit_model_builder::ModelBuilder::default()
.calendar("service1", &["2021-03-14", "2021-05-04"])
.vj("vj1", |vj| {
vj.calendar("service1")
.st("SP1", "10:00:00", "10:01:00")
.st("SP2", "11:00:00", "11:01:00");
})
.vj("vj2", |vj| {
vj.calendar("service1")
.st("SP3", "12:00:00", "12:01:00")
.st("SP4", "13:00:00", "13:01:00");
})
.build();
let service1_idx = model.calendars.get_idx("service1").unwrap();
let vj1_idx = model.vehicle_journeys.get_idx("vj1").unwrap();
let vj2_idx = model.vehicle_journeys.get_idx("vj2").unwrap();

// Add a new calendar
let service2_idx = model
.add_calendar(Calendar {
id: "service2".to_string(),
..Default::default()
})
.unwrap();
model
.connect_calendar_to_vehicle_journeys(service2_idx, vec![vj2_idx])
.unwrap();

// Verify that 'service2' is accessible from 'vj2'
let calendar_indexes: IdxSet<Calendar> = model.get_corresponding_from_idx(vj2_idx);
assert_eq!(*calendar_indexes.iter().next().unwrap(), service2_idx);

// Verify that 'vj2' is accessible from 'service2'
let vj_indexes: IdxSet<VehicleJourney> = model.get_corresponding_from_idx(service2_idx);
assert_eq!(*vj_indexes.iter().next().unwrap(), vj2_idx);

// Verify that only 'vj1' is accessible from 'service1' now ('vj2' is not anymore)
let vj_indexes: IdxSet<VehicleJourney> = model.get_corresponding_from_idx(service1_idx);
assert_eq!(*vj_indexes.iter().next().unwrap(), vj1_idx);
}
}

impl ::serde::Serialize for Model {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down