mirror of https://github.com/jackwener/wx-cli.git
2.3 KiB
2.3 KiB
| estimated_steps | estimated_files | skills_used |
|---|---|---|
| 16 | 2 |
T01: Create transport module with traits, generic handler, and TCP implementation
Why: Establish the transport abstraction layer — the core deliverable of S01. Define traits that abstract over Unix socket, Windows named pipe, and TCP. Extract the duplicated JSON-line protocol handling from server.rs into a generic handle_connection function.
Steps:
- Create
src/transport/mod.rswith module declarations - Define
TransportAddrenum with variants:Unix(PathBuf),WindowsPipe(String),Tcp(SocketAddr) - Define
Listenertrait (object-safe):type Stream(Send + AsyncRead + AsyncWrite + Unpin),async fn accept(&mut self) -> Result<Self::Stream> - Define
Connectortrait (object-safe): sameStreamtype,async fn connect(&self, addr: &TransportAddr) -> Result<Self::Stream> - Implement
handle_connection<S>as an async generic function acceptingS: AsyncRead + AsyncWrite + Unpin,&DbCache,&Arc<tokio::sync::RwLock<Arc<Names>>>— reads one JSON line, parsesRequest, callsdispatch, writes one JSON-lineResponse(extracted from current handle_connection_unix/handle_connection_windows in server.rs) - Implement
struct TcpListenerwrappingtokio::net::TcpListenerwithListenerimpl - Implement
struct TcpConnectorwithConnectorimpl usingtokio::net::TcpStream - Add
pub mod transport;tosrc/main.rs - Keep existing server.rs/handler functions untouched at this point (moved in T02)
Constraints:
ListenerandConnectormust be object-safe (noSelfin method params/returns beyond standard patterns)handle_connectionmust bepub(crate)for server.rs to use- Do NOT modify ipc.rs (protocol types are already well-abstracted)
- TcpListener/TcpConnector use std
tokio::net— already available as dependency
Inputs
src/ipc.rssrc/daemon/server.rssrc/daemon/cache.rssrc/daemon/query.rsCargo.toml
Expected Output
src/transport/mod.rs
Verification
cargo check && test -f src/transport/mod.rs && grep -q "pub trait Listener" src/transport/mod.rs && grep -q "pub trait Connector" src/transport/mod.rs && grep -q "pub async fn handle_connection" src/transport/mod.rs && grep -q "pub struct TcpListener" src/transport/mod.rs && grep -q "pub struct TcpConnector" src/transport/mod.rs