Skip to content

Commit

Permalink
Split project into multiple crates.
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Dec 30, 2024
1 parent 2f208f7 commit fdb0676
Show file tree
Hide file tree
Showing 42 changed files with 1,151 additions and 207 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ jobs:
run: |
set -eufo pipefail
cargo fmt --all --check
cargo clippy
cargo clippy --workspace
cargo check --workspace
cargo build --workspace
cargo test --all-targets
cargo test --doc
cargo test --workspace
cargo test --workspace --doc
benchmarks:
runs-on: ubuntu-24.04
Expand All @@ -64,7 +64,7 @@ jobs:
cachix-auth-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Build benchmarks
run: cargo codspeed build
run: cargo codspeed build --workspace

- name: Upload benchmark results to CodSpeed
uses: CathalMullan/action@main
Expand All @@ -91,7 +91,7 @@ jobs:
cachix-auth-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Generate coverage
run: cargo llvm-cov --doctests --codecov --output-path codecov.json
run: cargo llvm-cov --workspace --doctests --codecov --output-path codecov.json

- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v4
Expand All @@ -118,7 +118,7 @@ jobs:
cachix-auth-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Build wayfind
run: cargo build
run: cargo build ---package wayfind

wasm:
runs-on: ubuntu-24.04
Expand All @@ -138,7 +138,7 @@ jobs:
cachix-auth-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Build wayfind
run: cargo build --target wasm32-unknown-unknown
run: cargo build ---package wayfind --target wasm32-unknown-unknown

oci:
runs-on: ubuntu-24.04
Expand Down
26 changes: 26 additions & 0 deletions Cargo.lock

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

21 changes: 16 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ similar.opt-level = 3
lto = "fat"
codegen-units = 1

[workspace.dependencies]
# Data Structures
smallvec = { version = "1.13", features = ["const_generics", "union"] }

# Testing
# NOTE: Keep in sync with `cargo-insta` Nix package.
insta = "=1.41.1"
similar-asserts = "1.6"

# https://doc.rust-lang.org/cargo/reference/manifest.html
[package]
name = "wayfind"
Expand Down Expand Up @@ -85,16 +94,18 @@ categories.workspace = true
workspace = true

[dependencies]
# Data Structures
smallvec = { version = "1.13", features = ["const_generics", "union"] }
wayfind-path = { path = "crates/path" }
wayfind-percent = { path = "crates/percent" }
wayfind-punycode = { path = "crates/punycode" }

smallvec = { workspace = true }

[dev-dependencies]
wayfind-rails-macro = { path = "crates/rails-macro" }

# Testing
# NOTE: Keep in sync with `cargo-insta` Nix package.
insta = "=1.41.1"
similar-asserts = "1.6"
insta = { workspace = true }
similar-asserts = { workspace = true }

# Encoding
percent-encoding = "2.3"
Expand Down
23 changes: 23 additions & 0 deletions crates/path/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# https://doc.rust-lang.org/cargo/reference/manifest.html
[package]
name = "wayfind-path"
description = "Path router for `wayfind`."
publish = false

version.workspace = true
authors.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true

[lints]
workspace = true

[dependencies]
smallvec = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
similar-asserts = { workspace = true }
File renamed without changes.
2 changes: 1 addition & 1 deletion src/router/path/delete.rs → crates/path/src/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{
node::Node,
state::{State, StaticState},
};
use crate::router::path::parser::{ParsedTemplate, Part};
use crate::parser::{ParsedTemplate, Part};

impl<S: State> Node<'_, S> {
/// Deletes a route from the node tree.
Expand Down
2 changes: 1 addition & 1 deletion src/router/path/display.rs → crates/path/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::router::path::{node::Node, state::State};
use crate::{node::Node, state::State};
use std::fmt::{Display, Write};

impl<S: State> Display for Node<'_, S> {
Expand Down
17 changes: 17 additions & 0 deletions crates/path/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub mod constraint;
pub use constraint::ConstraintError;

pub mod delete;
pub use delete::DeleteError;

pub mod encoding;
pub use encoding::EncodingError;

pub mod insert;
pub use insert::InsertError;

pub mod search;
pub use search::SearchError;

pub mod template;
pub use template::TemplateError;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{error::Error, fmt::Display};

/// Errors relating to constraints.
#[derive(Debug, PartialEq, Eq)]
pub enum PathConstraintError {
pub enum ConstraintError {
/// Constraint name is already in use.
///
/// # Examples
Expand Down Expand Up @@ -42,9 +42,9 @@ pub enum PathConstraintError {
},
}

impl Error for PathConstraintError {}
impl Error for ConstraintError {}

impl Display for PathConstraintError {
impl Display for ConstraintError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::DuplicateName {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use super::PathTemplateError;
use super::TemplateError;
use crate::errors::EncodingError;
use std::{error::Error, fmt::Display};

/// Errors relating to attempting to delete a route from a [`Router`](crate::Router).
#[derive(Debug, PartialEq, Eq)]
pub enum PathDeleteError {
pub enum DeleteError {
/// A [`EncodingError`] that occurred during the decoding.
EncodingError(EncodingError),

/// A [`RouteError`] that occurred during the delete.
TemplateError(PathTemplateError),
TemplateError(TemplateError),

/// Route to be deleted was not found in the router.
///
Expand Down Expand Up @@ -68,9 +68,9 @@ pub enum PathDeleteError {
},
}

impl Error for PathDeleteError {}
impl Error for DeleteError {}

impl Display for PathDeleteError {
impl Display for DeleteError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::EncodingError(error) => error.fmt(f),
Expand All @@ -96,14 +96,14 @@ The route must be deleted using the same format as was inserted"
}
}

impl From<EncodingError> for PathDeleteError {
impl From<EncodingError> for DeleteError {
fn from(error: EncodingError) -> Self {
Self::EncodingError(error)
}
}

impl From<PathTemplateError> for PathDeleteError {
fn from(error: PathTemplateError) -> Self {
impl From<TemplateError> for DeleteError {
fn from(error: TemplateError) -> Self {
Self::TemplateError(error)
}
}
106 changes: 106 additions & 0 deletions crates/path/src/errors/encoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use std::{error::Error, fmt::Display};

/// Errors relating to attempting to decode strings.
#[derive(Debug, PartialEq, Eq)]
pub enum EncodingError {
/// Invalid percent-encoding character encountered.
///
/// # Examples
///
/// ```rust
/// use wayfind::errors::PercentEncodingError;
///
/// let error = PercentEncodingError::InvalidCharacter {
/// input: "/hello%GGworld".to_string(),
/// position: 6,
/// character: vec![b'%', b'G', b'G'],
/// };
///
/// let display = "
/// invalid character
///
/// Input: /hello%GGworld
/// ^^^
///
/// Expected: '%' followed by two hexadecimal digits (a-F, 0-9)
/// Found: '%GG'
/// ";
///
/// assert_eq!(error.to_string(), display.trim());
/// ```
InvalidCharacter {
/// The unaltered input string.
input: String,
/// The position in the input where the invalid encoding was found.
position: usize,
/// The invalid character sequence.
character: Vec<u8>,
},

/// Invalid UTF-8 sequence encountered.
///
/// # Examples
///
/// ```rust
/// use wayfind::errors::EncodingError;
///
/// let error = EncodingError::Utf8Error {
/// input: "hello�world".to_string(),
/// };
///
/// let display = "
/// invalid UTF-8 sequence
///
/// Input: hello�world
///
/// Expected: valid UTF-8 characters
/// Found: invalid byte sequence
/// ";
///
/// assert_eq!(error.to_string(), display.trim());
/// ```
Utf8Error {
/// The invalid input.
/// This will contain UTF-8 replacement symbols.
input: String,
},
}

impl Error for EncodingError {}

impl Display for EncodingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidCharacter {
input,
position,
character,
} => {
let character = String::from_utf8_lossy(character);
let arrow = " ".repeat(*position) + &"^".repeat(character.len());

write!(
f,
"invalid character
Input: {input}
{arrow}
Expected: '%' followed by two hexadecimal digits (a-F, 0-9)
Found: '{character}'",
)
}
Self::Utf8Error { input } => {
write!(
f,
"invalid UTF-8 sequence
Input: {input}
Expected: valid UTF-8 characters
Found: invalid byte sequence",
)
}
}
}
}
Loading

0 comments on commit fdb0676

Please sign in to comment.