# CLAUDE.md -- Rust Project Conventions
## Philosophy
Functional, type-driven, domain-driven.
## Architecture
- Modules by domain context.
- One module per concern (method, headers, url, request, response, transport, fetch).
- Thin lib.rs that exposes `fetch(request)`.
## Types
- Newtypes for `Method`, `StatusCode`.
- Sum types for `HeaderName`, `Error`.
- No public struct fields.
- `#[must_use]` on getters.
## Error Handling
- Single project-wide `Error` enum.
- Display + std::error::Error impls by hand; no thiserror, no anyhow.
- Never panic.
## Style
- Prefer match over if/else, except on bool.
- No `return` keyword.
- No `mut` (exception: minimal `let mut` at the `TcpStream::read_to_end` FFI boundary).
- Combinators over loops.
- Never match on Option<_>; use combinators.
- No unwrap()/expect() anywhere.
- No loop or for.
- No scan.
- No Rc/Arc.
- No naked `as` casts.
- Exhaustive matches; no `_` wildcard arm on enums.
## Traits
- No dyn Trait.
- Implement standard traits over ad-hoc methods.
## Linting
```toml
[lints.clippy]
all = { level = "deny", priority = -1 }
pedantic = { level = "warn", priority = -1 }
needless_pass_by_value = "warn"
manual_map = "warn"
```
## Verification
- Always run `RUSTFLAGS="-D warnings" cargo clippy --all-targets`.
- Always run `cargo fmt`.
## Testing
- Tests return `Result<(), Error>` and propagate failures with `?`.
- No assert!, no `assert_eq!`, no panic!, no `unreachable!`, no unwrap, no expect.
- All tests are offline parser / type tests (no network requests in CI).
## Dependencies
- No runtime dependencies. All HTTP/1.1 framing is local; TLS is deferred to v0.2 behind a `tls` feature.
- `proptest` dev-dep.
- No path dependencies.
## Documentation
- `///` doc comments on every public item.
- `# Examples` with runnable code blocks (offline-safe).
## Layer context
This crate is the **network** in the Servo-replacement webview stack:
1. `html-cat`, `css-cat`, `dom-cat`, `layout-cat`, `paint-cat` -- rendering pipeline.
2. **`net-cat`** -- HTTP/1.1 client.
3. `web-api-cat` -- bindings between boa-cat Values and DOM / fetch.
4. `tauri-runtime-servocat` -- meta-crate.
## v0 scope
- `Method` (`GET`/`POST`/`PUT`/`DELETE`/`HEAD`/`OPTIONS`/`PATCH`).
- `Url` parser for `http://host[:port]/path?query` (plain HTTP only; `https` returns `Error::UnsupportedScheme`).
- `Headers` (case-insensitive name lookup, ordered list).
- `Request` and `Response` types with status, headers, body bytes.
- `fetch(request)` connects via TCP, writes the request, reads until EOF (`Connection: close` forced), parses the response.
- Automatic `Host`, `User-Agent`, and `Content-Length` headers.
## Deferred to v0.2+
- HTTPS (TLS) via `rustls` behind a feature flag.
- Connection keep-alive / pooling.
- Chunked transfer encoding (we rely on `Connection: close` + read-to-EOF).
- Redirects.
- Cookies.
- Streaming bodies.
- Async (this is a synchronous client).