Skip to content

Commit

Permalink
Merge pull request #107 from nyurik/lints
Browse files Browse the repository at this point in the history
A bit of linting
  • Loading branch information
ianthetechie authored May 9, 2024
2 parents 69b2a4a + 836d65d commit 2adc570
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 56 deletions.
34 changes: 17 additions & 17 deletions apple/Sources/UniFFI/ferrostar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,10 @@ public func FfiConverterTypeNavigationController_lower(_ value: NavigationContro
* over a generic request/response flow (typically over a network;
* local/offline routers **do not use this object** as the interaction patterns are different).
*
* This is essentially the composite of the [RouteRequestGenerator] and [RouteResponseParser]
* This is essentially the composite of the [`RouteRequestGenerator`] and [`RouteResponseParser`]
* traits, but it provides one further level of abstraction which is helpful to consumers.
* As there is no way to signal compatibility between request generators and response parsers,
* the [RouteAdapter] provides convenience constructors which take the guesswork out of it,
* the [`RouteAdapter`] provides convenience constructors which take the guesswork out of it,
* while still leaving consumers free to implement one or both halves.
*
* In the future, we may provide additional methods or conveniences, and this
Expand All @@ -615,10 +615,10 @@ public protocol RouteAdapterProtocol: AnyObject {
* over a generic request/response flow (typically over a network;
* local/offline routers **do not use this object** as the interaction patterns are different).
*
* This is essentially the composite of the [RouteRequestGenerator] and [RouteResponseParser]
* This is essentially the composite of the [`RouteRequestGenerator`] and [`RouteResponseParser`]
* traits, but it provides one further level of abstraction which is helpful to consumers.
* As there is no way to signal compatibility between request generators and response parsers,
* the [RouteAdapter] provides convenience constructors which take the guesswork out of it,
* the [`RouteAdapter`] provides convenience constructors which take the guesswork out of it,
* while still leaving consumers free to implement one or both halves.
*
* In the future, we may provide additional methods or conveniences, and this
Expand Down Expand Up @@ -965,7 +965,7 @@ public func FfiConverterTypeRouteDeviationDetector_lower(_ value: RouteDeviation
}

/**
* A trait describing any object capable of generating [RouteRequest]s.
* A trait describing any object capable of generating [`RouteRequest`]s.
*
* The interface is intentionally generic. Every routing backend has its own set of
* parameters, including a "profile," max travel speed, units of speed and distance, and more.
Expand All @@ -986,7 +986,7 @@ public protocol RouteRequestGenerator: AnyObject {
}

/**
* A trait describing any object capable of generating [RouteRequest]s.
* A trait describing any object capable of generating [`RouteRequest`]s.
*
* The interface is intentionally generic. Every routing backend has its own set of
* parameters, including a "profile," max travel speed, units of speed and distance, and more.
Expand Down Expand Up @@ -2406,9 +2406,9 @@ public func FfiConverterTypeVisualInstructionContent_lower(_ value: VisualInstru
/**
* A waypoint along a route.
*
* Within the context of Ferrostar, a route request consists of exactly one [UserLocation]
* Within the context of Ferrostar, a route request consists of exactly one [`UserLocation`]
* and at least one [Waypoint]. The route starts from the user's location (which may
* contain other useful information like their current course for the [crate::routing_adapters::RouteRequestGenerator]
* contain other useful information like their current course for the [`crate::routing_adapters::RouteRequestGenerator`]
* to use) and proceeds through one or more waypoints.
*
* Waypoints are used during route calculation, are tracked throughout the lifecycle of a trip,
Expand Down Expand Up @@ -2473,7 +2473,7 @@ public func FfiConverterTypeWaypoint_lower(_ value: Waypoint) -> RustBuffer {
// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
/**
* Specifies additional information about a [ManeuverType]
* Specifies additional information about a [`ManeuverType`]
*/
public enum ManeuverModifier {
case uTurn
Expand Down Expand Up @@ -2556,7 +2556,7 @@ extension ManeuverModifier: Equatable, Hashable {}
/**
* Indicates the type of maneuver to perform.
*
* Frequently used in conjunction with [ManeuverModifier].
* Frequently used in conjunction with [`ManeuverModifier`].
*/
public enum ManeuverType {
case turn
Expand Down Expand Up @@ -2865,7 +2865,7 @@ public func FfiConverterTypeRouteDeviationTracking_lower(_ value: RouteDeviation
// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
/**
* A route request generated by a [RouteRequestGenerator].
* A route request generated by a [`RouteRequestGenerator`].
*/
public enum RouteRequest {
case httpPost(
Expand Down Expand Up @@ -3071,7 +3071,7 @@ public enum StepAdvanceMode {
minimumHorizontalAccuracy: UInt16,
/**
* At this (optional) distance, navigation should advance to the next step regardless
* of which LineString appears closer.
* of which `LineString` appears closer.
*/
automaticAdvanceDistance: UInt16?
)
Expand Down Expand Up @@ -3704,7 +3704,7 @@ public func advanceLocationSimulation(state: LocationSimulationState) -> Locatio
}

/**
* Creates a [RouteResponseParser] capable of parsing OSRM responses.
* Creates a [`RouteResponseParser`] capable of parsing OSRM responses.
*
* This response parser is designed to be fairly flexible,
* supporting both vanilla OSRM and enhanced Valhalla (ex: from Stadia Maps and Mapbox) outputs
Expand All @@ -3721,10 +3721,10 @@ public func createOsrmResponseParser(polylinePrecision: UInt32) -> RouteResponse
}

/**
* Creates a [RouteRequestGenerator]
* Creates a [`RouteRequestGenerator`]
* which generates requests to an arbitrary Valhalla server (using the OSRM response format).
*
* This is provided as a convenience for use from foreign code when creating your own [routing_adapters::RouteAdapter].
* This is provided as a convenience for use from foreign code when creating your own [`routing_adapters::RouteAdapter`].
*/
public func createValhallaRequestGenerator(endpointUrl: String, profile: String) -> RouteRequestGenerator {
try! FfiConverterTypeRouteRequestGenerator.lift(
Expand Down Expand Up @@ -3825,10 +3825,10 @@ private var initializationResult: InitializationResult {
if uniffi_ferrostar_checksum_func_advance_location_simulation() != 62608 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_ferrostar_checksum_func_create_osrm_response_parser() != 28097 {
if uniffi_ferrostar_checksum_func_create_osrm_response_parser() != 46856 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_ferrostar_checksum_func_create_valhalla_request_generator() != 35701 {
if uniffi_ferrostar_checksum_func_create_valhalla_request_generator() != 27528 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_ferrostar_checksum_func_get_route_polyline() != 53320 {
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[workspace]

members = [
"uniffi-bindgen",
"ferrostar",
Expand All @@ -11,7 +10,7 @@ authors = ["Ian Wagner <ian@stadiamaps.com>", "Jacob Fielding <jacob@rallista.ap
license = "BSD-3-Clause"
edition = "2021"
repository = "https://github.com/stadiamaps/ferrostar"
rust-version = "1.74.0"
rust-version = "1.75.0"

[profile.dev.package]
insta.opt-level = 3
Expand All @@ -22,4 +21,17 @@ lto = "thin"
opt-level = "s"

[workspace.dependencies]
uniffi = "0.26.1"
uniffi = "0.26.1"

[workspace.lints.rust]
unsafe_code = "forbid"
unused_qualifications = "warn"

[workspace.lints.clippy]
pedantic = { level = "warn", priority = -1 }
cast_possible_truncation = "allow"
cast_precision_loss = "allow"
cast_sign_loss = "allow"
missing_errors_doc = "allow"
module_name_repetitions = "allow"
must_use_candidate = "allow"
2 changes: 2 additions & 0 deletions common/ferrostar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
lints.workspace = true

[package]
name = "ferrostar"
version = "0.0.31"
Expand Down
10 changes: 5 additions & 5 deletions common/ferrostar/src/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn snap_user_location_to_line(location: UserLocation, line: &LineString) ->
///
/// The `decimal_digits` parameter refers to the number of digits after the point.
pub(crate) fn trunc_float(value: f64, decimal_digits: u32) -> f64 {
let factor = 10i64.pow(decimal_digits) as f64;
let factor = 10_i64.pow(decimal_digits) as f64;
(value * factor).round() / factor
}

Expand All @@ -60,7 +60,7 @@ fn snap_point_to_line(point: &Point, line: &LineString) -> Option<Point> {
// Bail early when we have two essentially identical points.
// This can cause some issues with edge cases (captured in proptest regressions)
// with the underlying libraries.
if line.euclidean_distance(point) < 0.000001 {
if line.euclidean_distance(point) < 0.000_001 {
return Some(*point);
}

Expand Down Expand Up @@ -113,7 +113,7 @@ fn is_close_enough_to_end_of_linestring(
/// Determines whether the navigation controller should complete the current route step
/// and move to the next.
///
/// NOTE: The [UserLocation] should *not* be snapped.
/// NOTE: The [`UserLocation`] should *not* be snapped.
pub fn should_advance_to_next_step(
current_step_linestring: &LineString,
next_route_step: Option<&RouteStep>,
Expand All @@ -134,7 +134,7 @@ pub fn should_advance_to_next_step(
is_close_enough_to_end_of_linestring(
&current_position,
current_step_linestring,
distance as f64,
f64::from(distance),
)
}
}
Expand All @@ -150,7 +150,7 @@ pub fn should_advance_to_next_step(
if is_close_enough_to_end_of_linestring(
&current_position,
current_step_linestring,
distance as f64,
f64::from(distance),
) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion common/ferrostar/src/deviation_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl RouteDeviationTracking {
minimum_horizontal_accuracy,
max_acceptable_deviation,
} => {
if location.horizontal_accuracy < *minimum_horizontal_accuracy as f64 {
if location.horizontal_accuracy < f64::from(*minimum_horizontal_accuracy) {
// Check if the deviation from the route line is within tolerance,
// after sanity checking that the positioning signal is within accuracy tolerance.
deviation_from_line(
Expand Down
8 changes: 4 additions & 4 deletions common/ferrostar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl UniffiCustomTypeConverter for Uuid {
type Builtin = String;

fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Uuid::from_str(&val).map_err(|e| e.into())
Ok(Uuid::from_str(&val)?)
}

fn from_custom(obj: Self) -> Self::Builtin {
Expand All @@ -47,10 +47,10 @@ impl UniffiCustomTypeConverter for Uuid {
// Instead, we use top-level functions to return dynamic objects conforming to the trait.
//

/// Creates a [RouteRequestGenerator]
/// Creates a [`RouteRequestGenerator`]
/// which generates requests to an arbitrary Valhalla server (using the OSRM response format).
///
/// This is provided as a convenience for use from foreign code when creating your own [routing_adapters::RouteAdapter].
/// This is provided as a convenience for use from foreign code when creating your own [`routing_adapters::RouteAdapter`].
#[uniffi::export]
fn create_valhalla_request_generator(
endpoint_url: String,
Expand All @@ -59,7 +59,7 @@ fn create_valhalla_request_generator(
Arc::new(ValhallaHttpRequestGenerator::new(endpoint_url, profile))
}

/// Creates a [RouteResponseParser] capable of parsing OSRM responses.
/// Creates a [`RouteResponseParser`] capable of parsing OSRM responses.
///
/// This response parser is designed to be fairly flexible,
/// supporting both vanilla OSRM and enhanced Valhalla (ex: from Stadia Maps and Mapbox) outputs
Expand Down
19 changes: 11 additions & 8 deletions common/ferrostar/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ impl From<GeographicCoordinate> for Point {

/// A waypoint along a route.
///
/// Within the context of Ferrostar, a route request consists of exactly one [UserLocation]
/// Within the context of Ferrostar, a route request consists of exactly one [`UserLocation`]
/// and at least one [Waypoint]. The route starts from the user's location (which may
/// contain other useful information like their current course for the [crate::routing_adapters::RouteRequestGenerator]
/// contain other useful information like their current course for the [`crate::routing_adapters::RouteRequestGenerator`]
/// to use) and proceeds through one or more waypoints.
///
/// Waypoints are used during route calculation, are tracked throughout the lifecycle of a trip,
Expand Down Expand Up @@ -215,10 +215,13 @@ pub struct RouteStep {
impl RouteStep {
// TODO: Memoize or something later
pub(crate) fn get_linestring(&self) -> LineString {
LineString::from_iter(self.geometry.iter().map(|coord| Coord {
x: coord.lng,
y: coord.lat,
}))
self.geometry
.iter()
.map(|coord| Coord {
x: coord.lng,
y: coord.lat,
})
.collect()
}

/// Gets the active visual instruction given the user's progress along the step.
Expand Down Expand Up @@ -276,7 +279,7 @@ pub struct SpokenInstruction {

/// Indicates the type of maneuver to perform.
///
/// Frequently used in conjunction with [ManeuverModifier].
/// Frequently used in conjunction with [`ManeuverModifier`].
#[derive(Deserialize, Debug, Copy, Clone, Eq, PartialEq, uniffi::Enum)]
#[cfg_attr(test, derive(Serialize))]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -306,7 +309,7 @@ pub enum ManeuverType {
ExitRotary,
}

/// Specifies additional information about a [ManeuverType]
/// Specifies additional information about a [`ManeuverType`]
#[derive(Deserialize, Debug, Copy, Clone, Eq, PartialEq, uniffi::Enum)]
#[cfg_attr(test, derive(Serialize))]
#[serde(rename_all = "lowercase")]
Expand Down
4 changes: 2 additions & 2 deletions common/ferrostar/src/navigation_controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
models::{Route, UserLocation},
};
use geo::{HaversineDistance, Point};
use models::*;
use models::{NavigationControllerConfig, StepAdvanceStatus, TripState};

/// Manages the navigation lifecycle of a route, reacting to inputs like user location updates
/// and returning a new state.
Expand All @@ -30,7 +30,7 @@ pub struct NavigationController {
impl NavigationController {
#[uniffi::constructor]
pub fn new(route: Route, config: NavigationControllerConfig) -> Self {
Self { config, route }
Self { route, config }
}

/// Returns initial trip state as if the user had just started the route with no progress.
Expand Down
2 changes: 1 addition & 1 deletion common/ferrostar/src/navigation_controller/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub enum StepAdvanceMode {
/// Values larger than this cannot trigger a step advance.
minimum_horizontal_accuracy: u16,
/// At this (optional) distance, navigation should advance to the next step regardless
/// of which LineString appears closer.
/// of which `LineString` appears closer.
automatic_advance_distance: Option<u16>,
},
}
Expand Down
8 changes: 4 additions & 4 deletions common/ferrostar/src/routing_adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod error;
pub mod osrm;
pub mod valhalla;

/// A route request generated by a [RouteRequestGenerator].
/// A route request generated by a [`RouteRequestGenerator`].
#[derive(PartialEq, Debug, uniffi::Enum)]
pub enum RouteRequest {
HttpPost {
Expand All @@ -22,7 +22,7 @@ pub enum RouteRequest {
},
}

/// A trait describing any object capable of generating [RouteRequest]s.
/// A trait describing any object capable of generating [`RouteRequest`]s.
///
/// The interface is intentionally generic. Every routing backend has its own set of
/// parameters, including a "profile," max travel speed, units of speed and distance, and more.
Expand Down Expand Up @@ -63,10 +63,10 @@ pub trait RouteResponseParser: Send + Sync {
/// over a generic request/response flow (typically over a network;
/// local/offline routers **do not use this object** as the interaction patterns are different).
///
/// This is essentially the composite of the [RouteRequestGenerator] and [RouteResponseParser]
/// This is essentially the composite of the [`RouteRequestGenerator`] and [`RouteResponseParser`]
/// traits, but it provides one further level of abstraction which is helpful to consumers.
/// As there is no way to signal compatibility between request generators and response parsers,
/// the [RouteAdapter] provides convenience constructors which take the guesswork out of it,
/// the [`RouteAdapter`] provides convenience constructors which take the guesswork out of it,
/// while still leaving consumers free to implement one or both halves.
///
/// In the future, we may provide additional methods or conveniences, and this
Expand Down
2 changes: 1 addition & 1 deletion common/ferrostar/src/routing_adapters/osrm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl RouteResponseParser for OsrmResponseParser {
distance: route.distance,
waypoints: waypoints.clone(),
steps,
})
});
}
}

Expand Down
Loading

0 comments on commit 2adc570

Please sign in to comment.