Task 10: TcpSource

rust crate railscale

Status

Completed 2026-03-29

What was implemented

TcpSource struct in locomotive/src/source.rs implementing the StreamSource trait from train_track.

Key details

  • Wraps tokio::net::TcpListener
  • bind(addr: &str) async constructor
  • local_addr() helper returning SocketAddr
  • accept() returns TcpStream
  • StreamSource trait uses RPITIT (async fn in traits, edition 2024)
  • type Error = std::io::Error (implements Into)

Files

  • locomotive/src/source.rs — implementation
  • locomotive/src/lib.rs — added mod source + pub use source::TcpSource
  • locomotive/tests/source_test.rs — integration test

Test pattern

Binds on port 0, spawns accept task, connects TcpStream client, writes “hello”, reads it back on the server-side stream via read_exact.