From f66b091699a7e68eccb947344fe042a3856f8f0c Mon Sep 17 00:00:00 2001 From: Chang Su Date: Fri, 2 Jan 2026 16:01:11 -0800 Subject: [PATCH] refactor(http): improve pd_types.rs documentation and style (#16319) --- sgl-model-gateway/src/routers/http/pd_types.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sgl-model-gateway/src/routers/http/pd_types.rs b/sgl-model-gateway/src/routers/http/pd_types.rs index 9cb6ad9e0..98f2144f3 100644 --- a/sgl-model-gateway/src/routers/http/pd_types.rs +++ b/sgl-model-gateway/src/routers/http/pd_types.rs @@ -1,4 +1,6 @@ -// Custom error type for PD router operations +//! Types and utilities for the prefill-decode (PD) disaggregated router. + +/// Custom error type for PD router operations #[derive(Debug, thiserror::Error)] pub enum PDRouterError { #[error("Worker already exists: {url}")] @@ -23,9 +25,9 @@ pub enum PDRouterError { Timeout { url: String }, } -// Helper functions for workers +/// Construct a full API URL from a base URL and path. pub fn api_path(url: &str, api_path: &str) -> String { - if api_path.starts_with("/") { + if api_path.starts_with('/') { format!("{}{}", url, api_path) } else { format!("{}/{}", url, api_path) @@ -34,7 +36,7 @@ pub fn api_path(url: &str, api_path: &str) -> String { use serde::Serialize; -// Optimized bootstrap wrapper for single requests +/// Optimized bootstrap wrapper for single requests. #[derive(Serialize)] pub struct RequestWithBootstrap<'a, T: Serialize> { #[serde(flatten)] @@ -44,7 +46,7 @@ pub struct RequestWithBootstrap<'a, T: Serialize> { pub bootstrap_room: u64, } -// Optimized bootstrap wrapper for batch requests +/// Optimized bootstrap wrapper for batch requests. #[derive(Serialize)] pub struct BatchRequestWithBootstrap<'a, T: Serialize> { #[serde(flatten)] @@ -54,13 +56,13 @@ pub struct BatchRequestWithBootstrap<'a, T: Serialize> { pub bootstrap_room: Vec, } -// Helper to generate bootstrap room ID +/// Generate a random bootstrap room ID. pub fn generate_room_id() -> u64 { // Generate a value in the range [0, 2^63 - 1] to match Python's random.randint(0, 2**63 - 1) rand::random::() & (i64::MAX as u64) } -// PD-specific routing policies +/// PD-specific routing policies. #[derive(Debug, Clone, PartialEq)] pub enum PDSelectionPolicy { Random,