Skip to content

Commit

Permalink
Import subcrates through the main crate (#6)
Browse files Browse the repository at this point in the history
The macro derive crate was generating code importing from the router
crate directly but the user is expected to import the main crate, not
the sub-crates
  • Loading branch information
JosephMoniz committed Oct 4, 2023
1 parent 3204210 commit fd64b10
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ shell: build-dev

.PHONY: build-ci
build-ci: build-dev
IMAGE=$(IMAGE) ./docker/run.sh cargo build
IMAGE=$(IMAGE) ./docker/run.sh cargo build --tests
sudo chmod -R ugo+rwx ./build-cache
docker save "$(IMAGE)" | gzip > ./build-cache/docker-image.tar.gz

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ both complex and straightforward use cases.
## Basic Usage

```rust
use front_line_router::{FrontLine, HttpVersion, RouterResult, Router};
use front_line::{FrontLine, HttpVersion, RouterResult, Router};

#[derive(FrontLine)]
enum MarketingRoutes {
Expand Down Expand Up @@ -103,4 +103,4 @@ following command.

```
make test
```
```
8 changes: 2 additions & 6 deletions front-line-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "front-line-derive"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
license = "MIT"
description = "Derive proc-macros for the front-line http router"
repository = "https://github.com/plasmaconduit/front-line/"
readme = "../README.md"
readme = "README.md"

[lib]
proc-macro = true
Expand All @@ -15,7 +15,3 @@ proc-macro2 = { workspace = true }
quote = { workspace = true }
regex = { workspace = true }
syn = { workspace = true }

[dev-dependencies]
front-line-router = { path = "../front-line-router" }
rstest = { workspace = true }
11 changes: 11 additions & 0 deletions front-line-derive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [DO NOT USE DIRECTLY](#do-not-use-directly)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# DO NOT USE DIRECTLY

import and use `front-line` instead.
2 changes: 1 addition & 1 deletion front-line-derive/src/capture_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> CaptureFields<'a> {
let parsed = format_ident!("parsed{base_offset}_{ident}");
let converted = format_ident!("converted{base_offset}_{ident}");
let conversion = quote! {
let #parsed: Option<#ty> = front_line_router::FromRoute::parse_path_variable(&#capture);
let #parsed: Option<#ty> = front_line::FromRoute::parse_path_variable(&#capture);
if #parsed.is_none() {
break #path_block;
}
Expand Down
7 changes: 5 additions & 2 deletions front-line-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Do not import or use this crate directly, import and use `front-line` instead.
//! See: [front-line](https://docs.rs/front-line/latest/front_line/)

mod capture_fields;
mod method_tag;
mod path;
Expand Down Expand Up @@ -56,9 +59,9 @@ pub fn front_line_derive(input: TokenStream) -> TokenStream {
})
.collect();
let router = quote! {
impl<#extended_params> front_line_router::Router<'de> for #name<#params> {
impl<#extended_params> front_line::Router<'de> for #name<#params> {
fn handle_parsed(
#method: front_line_router::Method,
#method: front_line::Method,
#remaining_path: &'de str
) -> Option<Self> {
#prefix_matcher
Expand Down
2 changes: 1 addition & 1 deletion front-line-derive/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Path {
let end = format_ident!("end{segment_offset}");
let capture = format_ident!("capture{base_offset}_{variable}");
quote! {
let #end = front_line_router::memchr::memchr(b'/', #last_slice.as_bytes()).unwrap_or(#last_slice.len());
let #end = front_line::memchr::memchr(b'/', #last_slice.as_bytes()).unwrap_or(#last_slice.len());
let #capture = &#last_slice[..#end];
let #next_slice = &#last_slice[#end..];
}
Expand Down
2 changes: 1 addition & 1 deletion front-line-derive/src/variant_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> VariantType<'a> {
.collect();
let method_ident = method.to_ident();
let by_method_matcher = quote! {
if #parsed_method == front_line_router::Method::#method_ident {
if #parsed_method == front_line::Method::#method_ident {
#(
#path_blocks
)*
Expand Down
4 changes: 2 additions & 2 deletions front-line-router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "front-line-router"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
license = "MIT"
description = "Traits and utilities for the front-line http router"
repository = "https://github.com/plasmaconduit/front-line/"
readme = "../README.md"
readme = "README.md"

[dependencies]
memchr = { workspace = true }
Expand Down
11 changes: 11 additions & 0 deletions front-line-router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [DO NOT USE DIRECTLY](#do-not-use-directly)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# DO NOT USE DIRECTLY

import and use [front-line](https://crates.io/crates/front-line) instead.
3 changes: 3 additions & 0 deletions front-line-router/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Do not import or use this crate directly, import and use `front-line` instead.
//! See: [front-line](https://docs.rs/front-line/latest/front_line/)

mod from_route;
mod http_version;
mod method;
Expand Down
7 changes: 6 additions & 1 deletion front-line/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "front-line"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
license = "MIT"
description = "A declarative, zero-copy HTTP router"
Expand All @@ -10,3 +10,8 @@ readme = "../README.md"
[dependencies]
front-line-router = { version = "0.1.0" }
front-line-derive = { version = "0.1.0"}
#front-line-router = { path = "../front-line-router" }
#front-line-derive = { path = "../front-line-derive"}

[dev-dependencies]
rstest = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use front_line_derive::FrontLine;
use front_line_router::{Error, HttpVersion, Router, RouterResult};
use front_line::{Error, FrontLine, HttpVersion, Router, RouterResult};
use rstest::rstest;

#[derive(PartialEq, Debug, FrontLine)]
Expand Down

0 comments on commit fd64b10

Please sign in to comment.