From de05609fee72840b32873f3c160a3452b255126d Mon Sep 17 00:00:00 2001 From: CatMe0w Date: Mon, 8 Jul 2024 21:57:37 -0600 Subject: [PATCH 1/2] Use camelCase for wasm-bindgen functions --- common/ferrostar/src/navigation_controller/mod.rs | 2 ++ common/ferrostar/src/routing_adapters/mod.rs | 4 +++- web/src/ferrostar-core.ts | 7 +++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common/ferrostar/src/navigation_controller/mod.rs b/common/ferrostar/src/navigation_controller/mod.rs index 7f010511..cfe7ca41 100644 --- a/common/ferrostar/src/navigation_controller/mod.rs +++ b/common/ferrostar/src/navigation_controller/mod.rs @@ -272,6 +272,7 @@ impl JsNavigationController { ))) } + #[wasm_bindgen(js_name = getInitialState)] pub fn get_initial_state(&self, location: JsValue) -> Result { let location: UserLocation = serde_wasm_bindgen::from_value(location)?; @@ -286,6 +287,7 @@ impl JsNavigationController { .map_err(|e| JsValue::from_str(&format!("{:?}", e))) } + #[wasm_bindgen(js_name = updateUserLocation)] pub fn update_user_location( &self, location: JsValue, diff --git a/common/ferrostar/src/routing_adapters/mod.rs b/common/ferrostar/src/routing_adapters/mod.rs index 8af2b594..521b31bf 100644 --- a/common/ferrostar/src/routing_adapters/mod.rs +++ b/common/ferrostar/src/routing_adapters/mod.rs @@ -186,7 +186,7 @@ impl RouteAdapter { pub struct JsRouteAdapter(RouteAdapter); #[cfg(feature = "wasm-bindgen")] -#[ wasm_bindgen(js_class = RouteAdapter)] +#[wasm_bindgen(js_class = RouteAdapter)] impl JsRouteAdapter { /// Creates a new RouteAdapter with a Valhalla HTTP request generator and an OSRM response parser. /// At the moment, this is the only supported combination. @@ -202,6 +202,7 @@ impl JsRouteAdapter { // TODO: We should have a better error handling strategy here. Same for the other methods. } + #[wasm_bindgen(js_name = generateRequest)] pub fn generate_request( &self, user_location: JsValue, @@ -226,6 +227,7 @@ impl JsRouteAdapter { } } + #[wasm_bindgen(js_name = parseResponse)] pub fn parse_response(&self, response: Vec) -> Result { match self.0.parse_response(response.into()) { Ok(routes) => serde_wasm_bindgen::to_value(&routes).map_err(JsValue::from), diff --git a/web/src/ferrostar-core.ts b/web/src/ferrostar-core.ts index 3e89b0d9..22ca9742 100644 --- a/web/src/ferrostar-core.ts +++ b/web/src/ferrostar-core.ts @@ -75,7 +75,7 @@ class FerrostarCore extends LitElement { await init(); this.routeAdapter = new RouteAdapter(this.valhallaEndpointUrl, this.profile); - const body = this.routeAdapter.generate_request(initialLocation, waypoints).get("body"); + const body = this.routeAdapter.generateRequest(initialLocation, waypoints).get("body"); // FIXME: assert httpClient is not null const response = await this.httpClient!(this.valhallaEndpointUrl, { method: "POST", @@ -83,7 +83,7 @@ class FerrostarCore extends LitElement { body: new Uint8Array(body).buffer, }); const responseData = new Uint8Array(await response.arrayBuffer()); - const routes = this.routeAdapter.parse_response(responseData); + const routes = this.routeAdapter.parseResponse(responseData); return routes; } @@ -107,8 +107,7 @@ class FerrostarCore extends LitElement { speed: null, }; - // FIXME: should be camelCase - const initialTripState = this.navigationController.get_initial_state(startingLocation); + const initialTripState = this.navigationController.getInitialState(startingLocation); this.handleStateUpdate(initialTripState, startingLocation); const polyline = L.polyline(route.geometry, { color: "red" }).addTo(this.map!); From 12923f68a6b97a49646634164160ec14079d4691 Mon Sep 17 00:00:00 2001 From: CatMe0w Date: Tue, 9 Jul 2024 14:39:08 -0600 Subject: [PATCH 2/2] Use camelCase for structs --- common/ferrostar/src/deviation_detection.rs | 2 ++ common/ferrostar/src/models.rs | 5 +++++ .../src/navigation_controller/models.rs | 4 ++++ web/index.html | 18 +++++++++--------- web/src/ferrostar-core.ts | 7 +++++-- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/common/ferrostar/src/deviation_detection.rs b/common/ferrostar/src/deviation_detection.rs index ba8c7eec..d4a457a4 100644 --- a/common/ferrostar/src/deviation_detection.rs +++ b/common/ferrostar/src/deviation_detection.rs @@ -44,6 +44,7 @@ pub enum RouteDeviationTracking { /// No checks will be done, and we assume the user is always following the route. None, /// Detects deviation from the route using a configurable static distance threshold from the route line. + #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] StaticThreshold { /// The minimum required horizontal accuracy of the user location, in meters. /// Values larger than this will not trigger route deviation warnings. @@ -115,6 +116,7 @@ pub enum RouteDeviation { /// The user is proceeding on course within the expected tolerances; everything is normal. NoDeviation, /// The user is off the expected route. + #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] OffRoute { /// The deviation from the route line, in meters. deviation_from_route_line: f64, diff --git a/common/ferrostar/src/models.rs b/common/ferrostar/src/models.rs index 9660ed5a..2db663ad 100644 --- a/common/ferrostar/src/models.rs +++ b/common/ferrostar/src/models.rs @@ -183,6 +183,7 @@ pub struct Speed { #[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] pub struct UserLocation { pub coordinates: GeographicCoordinate, /// The estimated accuracy of the coordinate (in meters) @@ -236,6 +237,7 @@ fn get_route_polyline(route: &Route, precision: u32) -> Result, /// The distance, in meters, to travel along the route after the maneuver to reach the next step. @@ -311,6 +313,7 @@ impl RouteStep { #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] pub struct SpokenInstruction { /// Plain-text instruction which can be synthesized with a TTS engine. pub text: String, @@ -387,6 +390,7 @@ pub enum ManeuverModifier { #[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] pub struct VisualInstructionContent { /// The text to display. pub text: String, @@ -406,6 +410,7 @@ pub struct VisualInstructionContent { #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(any(feature = "wasm-bindgen", test), derive(Serialize, Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] pub struct VisualInstruction { /// The primary instruction content. /// diff --git a/common/ferrostar/src/navigation_controller/models.rs b/common/ferrostar/src/navigation_controller/models.rs index d21e1420..6c180160 100644 --- a/common/ferrostar/src/navigation_controller/models.rs +++ b/common/ferrostar/src/navigation_controller/models.rs @@ -28,6 +28,7 @@ pub struct TripProgress { #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] #[cfg_attr(feature = "wasm-bindgen", derive(Serialize, Deserialize))] pub enum TripState { + #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] Navigating { snapped_user_location: UserLocation, /// The ordered list of steps that remain in the trip. @@ -81,6 +82,7 @@ pub enum StepAdvanceMode { /// You can use this to implement custom behaviors in external code. Manual, /// Automatically advances when the user's location is close enough to the end of the step + #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] DistanceToEndOfStep { /// Distance to the last waypoint in the step, measured in meters, at which to advance. distance: u16, @@ -90,6 +92,7 @@ pub enum StepAdvanceMode { }, /// Automatically advances when the user's distance to the *next* step's linestring is less /// than the distance to the current step's linestring. + #[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] RelativeLineStringDistance { /// The minimum required horizontal accuracy of the user location, in meters. /// Values larger than this cannot trigger a step advance. @@ -103,6 +106,7 @@ pub enum StepAdvanceMode { #[derive(Clone)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[cfg_attr(feature = "wasm-bindgen", derive(Deserialize))] +#[cfg_attr(feature = "wasm-bindgen", serde(rename_all = "camelCase"))] pub struct NavigationControllerConfig { pub step_advance: StepAdvanceMode, pub route_deviation_tracking: RouteDeviationTracking, diff --git a/web/index.html b/web/index.html index cb89d04c..d4334fbc 100644 --- a/web/index.html +++ b/web/index.html @@ -29,18 +29,18 @@