Skip to content

Commit

Permalink
Refactor crate API
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Aug 27, 2024
1 parent 3a35573 commit 0760335
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 38 deletions.
4 changes: 2 additions & 2 deletions benches/matchit_criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ fn benchmark(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("matchit benchmarks");

group.bench_function("matchit benchmarks/wayfind", |bencher| {
let mut router = wayfind::router::Router::new();
let mut router = wayfind::Router::new();
for route in routes!(brackets) {
router.insert(route, true).unwrap();
}

bencher.iter(|| {
for route in black_box(paths()) {
let path = wayfind::path::Path::new(route).unwrap();
let path = wayfind::Path::new(route).unwrap();
let output = black_box(router.search(black_box(&path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.parameters.iter().map(|p| (p.key, p.value)).collect());
Expand Down
4 changes: 2 additions & 2 deletions benches/matchit_divan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ fn main() {

#[divan::bench(name = "wayfind")]
fn wayfind(bencher: divan::Bencher) {
let mut router = wayfind::router::Router::new();
let mut router = wayfind::Router::new();
for route in routes!(brackets) {
router.insert(route, true).unwrap();
}

bencher.bench(|| {
for route in black_box(paths()) {
let path = wayfind::path::Path::new(route).unwrap();
let path = wayfind::Path::new(route).unwrap();
let output = black_box(router.search(black_box(&path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.parameters.iter().map(|p| (p.key, p.value)).collect());
Expand Down
4 changes: 2 additions & 2 deletions benches/path_tree_criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ fn benchmark(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("path-tree benchmarks");

group.bench_function("path-tree benchmarks/wayfind", |bencher| {
let mut router = wayfind::router::Router::new();
let mut router = wayfind::Router::new();
for (index, route) in routes!(brackets).iter().enumerate() {
router.insert(route, index).unwrap();
}

bencher.iter(|| {
for route in black_box(paths()) {
let path = wayfind::path::Path::new(route).unwrap();
let path = wayfind::Path::new(route).unwrap();
let output = black_box(router.search(black_box(&path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.parameters.iter().map(|p| (p.key, p.value)).collect());
Expand Down
4 changes: 2 additions & 2 deletions benches/path_tree_divan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ fn main() {

#[divan::bench(name = "wayfind")]
fn wayfind(bencher: divan::Bencher) {
let mut router = wayfind::router::Router::new();
let mut router = wayfind::Router::new();
for (index, route) in routes!(brackets).iter().enumerate() {
router.insert(route, index).unwrap();
}

bencher.bench(|| {
for route in black_box(paths()) {
let path = wayfind::path::Path::new(route).unwrap();
let path = wayfind::Path::new(route).unwrap();
let output = black_box(router.search(black_box(&path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.parameters.iter().map(|p| (p.key, p.value)).collect());
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-fork/src/routing/path_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use axum_core::response::IntoResponse;
use std::{borrow::Cow, collections::HashMap, convert::Infallible, fmt, sync::Arc};
use tower_layer::Layer;
use tower_service::Service;
use wayfind::{errors::insert::InsertError, node::search::Match, path::Path, router::Router};
use wayfind::{errors::InsertError, Match, Path, Router};

use super::{
future::RouteFuture, not_found::NotFound, strip_prefix::StripPrefix, url_params, Endpoint,
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-fork/src/routing/url_params.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::util::PercentDecodedStr;
use http::Extensions;
use std::sync::Arc;
use wayfind::node::search::Parameter;
use wayfind::Parameter;

#[derive(Clone)]
pub(crate) enum UrlParams {
Expand Down
2 changes: 1 addition & 1 deletion examples/hyper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
sync::Arc,
};
use tokio::{net::TcpListener, task::JoinSet};
use wayfind::{node::search::Parameter, path::Path, router::Router};
use wayfind::{Parameter, Path, Router};

type BoxFuture<'a> = Pin<
Box<
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
})
sccache
cargo-insta
cargo-watch

# Benchmarking
cargo-codspeed
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut router = wayfind::router::Router::new();
let mut router = wayfind::Router::new();
if let Ok(route) = std::str::from_utf8(data) {
let _ = router.insert(route, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/decode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::errors::decode::DecodeError;
use std::borrow::Cow;

pub(crate) fn percent_decode(input: &[u8]) -> Result<Cow<[u8]>, DecodeError> {
pub fn percent_decode(input: &[u8]) -> Result<Cow<[u8]>, DecodeError> {
if !input.contains(&b'%') {
return Ok(Cow::Borrowed(input));
}
Expand Down
19 changes: 14 additions & 5 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
pub mod constraint;
pub mod decode;
pub mod delete;
pub mod insert;
pub mod route;
pub(crate) mod constraint;
pub use constraint::ConstraintError;

pub(crate) mod decode;
pub use decode::DecodeError;

pub(crate) mod delete;
pub use delete::DeleteError;

pub(crate) mod insert;
pub use insert::InsertError;

pub(crate) mod route;
pub use route::RouteError;
24 changes: 17 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
//! TODO
//! Hello world!
pub(crate) mod constraints;
pub use constraints::Constraint;

pub(crate) mod decode;

pub mod constraints;
pub mod decode;
pub mod errors;
pub mod node;
pub mod parts;
pub mod path;
pub mod router;

pub(crate) mod node;
pub use node::search::{Match, Parameter};

pub(crate) mod parts;

pub(crate) mod path;
pub use path::Path;

pub(crate) mod router;
pub use router::Router;
8 changes: 2 additions & 6 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use std::{fmt::Debug, sync::Arc};
use wayfind::{
node::search::{Match, Parameter},
path::Path,
router::Router,
};
use wayfind::{Match, Parameter, Path, Router};

#[macro_export]
macro_rules! assert_router_matches {
Expand All @@ -28,7 +24,7 @@ macro_rules! assert_router_matches {
value: $value,
params: vec![
$(
$( wayfind::node::search::Parameter {
$( wayfind::Parameter {
key: $param_key,
value: $param_value,
} ),+
Expand Down
2 changes: 1 addition & 1 deletion tests/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::too_many_lines)]

use std::error::Error;
use wayfind::{constraints::Constraint, router::Router};
use wayfind::{Constraint, Router};

#[path = "./common.rs"]
mod common;
Expand Down
2 changes: 1 addition & 1 deletion tests/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::error::Error;
use wayfind::router::Router;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
Expand Down
2 changes: 1 addition & 1 deletion tests/matchit_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(clippy::too_many_lines, clippy::cognitive_complexity)]

use std::error::Error;
use wayfind::router::Router;
use wayfind::Router;

#[test]
fn normalized() -> Result<(), Box<dyn Error>> {
Expand Down
2 changes: 1 addition & 1 deletion tests/matchit_matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(clippy::too_many_lines)]

use std::error::Error;
use wayfind::router::Router;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
Expand Down
2 changes: 1 addition & 1 deletion tests/path_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(clippy::too_many_lines)]

use std::error::Error;
use wayfind::router::Router;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
Expand Down
2 changes: 1 addition & 1 deletion tests/poem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(clippy::too_many_lines)]

use std::error::Error;
use wayfind::{constraints::Constraint, router::Router};
use wayfind::{Constraint, Router};

#[path = "./common.rs"]
mod common;
Expand Down
2 changes: 1 addition & 1 deletion tests/uncommon.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::too_many_lines)]

use std::error::Error;
use wayfind::router::Router;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
Expand Down

0 comments on commit 0760335

Please sign in to comment.