Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ after formatting. Line numbers below refer to that file.

- [ ] Develop a minimal middleware system and extractor traits for payloads,
connection metadata, and shared state.
- [ ] Define `FromMessageRequest` for extractor types (lines 760-782).
- [ ] Provide built-in extractors `Message<T>`, `ConnectionInfo`, and
`SharedState<T>` (lines 792-840).
- [ ] Support custom extractors implementing `FromMessageRequest`
(lines 842-858).
- [ ] Implement middleware using `Transform`/`Service` traits and a simple
`from_fn` style variant (lines 866-899).
- [ ] Register middleware with `WireframeApp::wrap` and execute it in order
(lines 900-919).
- [ ] Document common middleware use cases like logging and authentication
(lines 920-935).

## 3. Initial Examples and Documentation

Expand Down
37 changes: 2 additions & 35 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl<T: Send + Sync> SharedState<T> {
/// ```
/// use std::sync::Arc;
/// use wireframe::extractor::SharedState;
///
/// let state = Arc::new(42);
/// let shared = SharedState::new(state.clone());
/// assert_eq!(*shared, 42);
Expand All @@ -97,28 +98,6 @@ impl<T: Send + Sync> From<T> for SharedState<T> {
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn advance_consumes_bytes() {
let mut payload = Payload { data: b"hello" };
payload.advance(2);
assert_eq!(payload.data, b"llo");
payload.advance(10);
assert!(payload.data.is_empty());
}

#[test]
fn remaining_reports_length() {
let mut payload = Payload { data: b"abc" };
assert_eq!(payload.remaining(), 3);
payload.advance(1);
assert_eq!(payload.remaining(), 2);
}
}

impl<T: Send + Sync> std::ops::Deref for SharedState<T> {
type Target = T;

Expand All @@ -131,21 +110,9 @@ impl<T: Send + Sync> std::ops::Deref for SharedState<T> {
/// ```
/// use std::sync::Arc;
/// use wireframe::extractor::SharedState;
/// let state = Arc::new(42);
/// let shared = SharedState::new(state.clone());
/// assert_eq!(*shared, 42);
/// Returns a reference to the inner shared state value.
///
/// Allows transparent access to the wrapped state as if it were a reference to the underlying type.
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use wireframe::extractor::SharedState;
///
/// let state = Arc::new(42);
/// let shared = SharedState::new(state);
/// let shared = SharedState::new(state.clone());
/// assert_eq!(*shared, 42);
/// ```
fn deref(&self) -> &Self::Target {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
///
/// # Examples
///
/// ```
/// ```ignore
/// # use your_crate::{Next, Service, ServiceRequest};
/// # struct MyService;
/// # impl Service for MyService {
Expand Down
10 changes: 6 additions & 4 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ where
/// If the CPU count cannot be determined, the server defaults to a single
/// worker.
///
/// ```no_run
/// ```ignore
/// use wireframe::{app::WireframeApp, server::WireframeServer};
///
/// let factory = || WireframeApp::new().unwrap();
/// let server = WireframeServer::new(factory);
/// ```
///
/// Creates a new `WireframeServer` with the provided factory closure.
///
/// The server is initialised with a default worker count equal to the number of available CPU cores, or 1 if this cannot be determined. The TCP listener is unset and must be configured with `bind` before running the server.
Expand All @@ -51,7 +53,7 @@ where
///
/// # Examples
///
/// ```
/// ```ignore
/// let server = WireframeServer::new(|| WireframeApp::default());
/// assert!(server.worker_count() >= 1);
/// ```
Expand Down Expand Up @@ -81,7 +83,7 @@ where
///
/// # Examples
///
/// ```
/// ```ignore
/// let server = WireframeServer::new(factory).workers(4);
/// assert_eq!(server.worker_count(), 4);
/// let server = server.workers(0);
Expand All @@ -99,7 +101,7 @@ where
///
/// # Examples
///
/// ```
/// ```ignore
/// let server = WireframeServer::new(factory);
/// assert!(server.worker_count() >= 1);
/// ```
Expand Down
Loading