Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

chore(server): Remove two unused functions, make others private (#52)

Graham King1a98edb5d923
diff --git a/crates/switchyard-server/src/lib.rs b/crates/switchyard-server/src/lib.rs
index 25771d6b6..d5d04805f 100644
--- a/crates/switchyard-server/src/lib.rs
+++ b/crates/switchyard-server/src/lib.rs
@@ -94,12 +94,13 @@ pub struct ServerRunOptions {
}
/// Builds a server state by loading and resolving a profile config path.
-pub fn state_from_config_path(path: impl AsRef<Path>) -> Result<ServerState> {
+fn state_from_config_path(path: impl AsRef<Path>) -> Result<ServerState> {
let document = parse_profile_config_path(path)?;
let plan = document.resolve()?;
ServerState::from_plan(&plan)
}
+/// Entry point to this module.
/// Loads config, optionally validates it, then starts the Rust server.
pub async fn run_server(options: ServerRunOptions) -> Result<()> {
let state = state_from_config_path(&options.config)?;
@@ -119,6 +120,7 @@ pub async fn run_server(options: ServerRunOptions) -> Result<()> {
}
/// Builds an Axum router with the same primary endpoint paths as the Python app.
+/// Public so that integration tests can see it.
pub fn build_switchyard_router(state: ServerState) -> Router {
Router::new()
.route("/v1/chat/completions", post(openai_chat_completions))
@@ -136,28 +138,13 @@ pub fn build_switchyard_router(state: ServerState) -> Router {
}
/// Serves a Switchyard router on an already-bound TCP listener.
-pub async fn serve(listener: TcpListener, state: ServerState) -> Result<()> {
+async fn serve(listener: TcpListener, state: ServerState) -> Result<()> {
axum::serve(listener, build_switchyard_router(state))
.with_graceful_shutdown(shutdown_signal())
.await
.map_err(server_io_error)
}
-/// Binds and serves a Switchyard router.
-pub async fn serve_addr(addr: SocketAddr, state: ServerState) -> Result<()> {
- serve_addr_with_backlog(addr, DEFAULT_LISTEN_BACKLOG, state).await
-}
-
-/// Binds with an explicit TCP listen backlog and serves a Switchyard router.
-pub async fn serve_addr_with_backlog(
- addr: SocketAddr,
- backlog: u32,
- state: ServerState,
-) -> Result<()> {
- let listener = bind_tcp_listener(addr, backlog)?;
- serve(listener, state).await
-}
-
fn bind_tcp_listener(addr: SocketAddr, backlog: u32) -> Result<TcpListener> {
let socket = if addr.is_ipv4() {
TcpSocket::new_v4()