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

A bit of linting #107

Merged
merged 4 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 <[email protected]>", "Jacob Fielding <[email protected]
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.30"
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 @@ -42,7 +42,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 @@ -57,7 +57,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 @@ -110,7 +110,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 @@ -131,7 +131,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 @@ -147,7 +147,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 @@ -202,10 +202,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 @@ -263,7 +266,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 @@ -293,7 +296,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 @@ -64,7 +64,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
9 changes: 5 additions & 4 deletions common/ferrostar/src/routing_adapters/osrm/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Route {
///
/// NOTE: This library assumes that 1) an overview geometry will always be requested, and
/// 2) that it will be a polyline (whether it is a polyline5 or polyline6 can be determined
/// by the [crate::routing_adapters::RouteResponseParser]).
/// by the [`crate::routing_adapters::RouteResponseParser`]).
pub geometry: String,
/// The legs between the given waypoints.
pub legs: Vec<RouteLeg>,
Expand Down Expand Up @@ -85,6 +85,7 @@ pub struct Annotation {
/// NOTE: This annotation is not in the official spec, but is a common extension used by Mapbox
/// and Valhalla.
#[serde(default, rename = "maxspeed")]
#[allow(dead_code)]
max_speed: Vec<MaxSpeed>,
}

Expand Down Expand Up @@ -185,7 +186,7 @@ pub struct StepManeuver {
/// A string indicating the type of maneuver.
///
/// Note that even though there are `new name` and `notification` instructions, the
/// `mode` and `name` (of the parent [RouteStep]) can change between *any* pair of instructions.
/// `mode` and `name` (of the parent [`RouteStep`]) can change between *any* pair of instructions.
/// They only offer a fallback in case there is nothing else to report.
/// TODO: Model this as an enum. Note that new types may be introduced, and anything unknown to the client should be handled like a turn.
#[serde(rename = "type")]
Expand All @@ -202,7 +203,7 @@ impl StepManeuver {
// Most commercial offerings offer server-side synthesis of voice instructions.
// However, we might consider synthesizing these locally too.
// This will be rather cumbersome with localization though.
fn synthesize_instruction(&self, locale: &str) -> String {
fn synthesize_instruction(&self, _locale: &str) -> String {
String::from("TODO: OSRM instruction synthesis")
}

Expand Down Expand Up @@ -269,7 +270,7 @@ pub struct Lane {

#[derive(Deserialize, Debug)]
pub struct Waypoint {
/// THe name of the street that the waypoint snapped to.
/// The name of the street that the waypoint snapped to.
pub name: Option<String>,
/// The distance (in meters) between the snapped point and the input coordinate.
pub distance: Option<f64>,
Expand Down
2 changes: 1 addition & 1 deletion common/ferrostar/src/routing_adapters/valhalla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;

/// A route request generator for Valhalla backends operating over HTTP.
///
/// Valhalla supports the [WaypointKind] field of [Waypoint]s. Variants have the same meaning as their
/// Valhalla supports the [`WaypointKind`] field of [Waypoint]s. Variants have the same meaning as their
/// [`type` strings in Valhalla API](https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#locations)
/// having the same name.
#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions common/uniffi-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
lints.workspace = true

[package]
name = "uniffi-bindgen"
version = "0.1.0"
authors.workspace = true
license.workspace = true
edition.workspace = true
repository.workspace = true
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
publish = false

[dependencies]
uniffi = { workspace = true, features = ["cli"] }
Expand Down
2 changes: 1 addition & 1 deletion common/uniffi-bindgen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_main()
uniffi::uniffi_bindgen_main();
}
Loading