@@ -157,6 +157,12 @@ impl RailConfigBuilder {
157157 }
158158 content. push_str ( & format ! ( "max_backups = {}\n " , config. max_backups) ) ;
159159
160+ // === Formatting ===
161+ content. push_str ( & format ! (
162+ "sort_dependencies = {} # false to preserve existing order\n " ,
163+ config. sort_dependencies
164+ ) ) ;
165+
160166 self . sections . push ( format ! ( "[unify]\n {}" , content) ) ;
161167
162168 self
@@ -253,13 +259,16 @@ impl RailConfigBuilder {
253259pub struct WorkspaceDepsBuilder {
254260 formatter : TomlFormatter ,
255261 deps : Vec < ( String , String , Option < String > ) > , // Name, Value (formatted), Optional comment
262+ /// Whether to sort dependencies alphabetically (default: true)
263+ pub sort_dependencies : bool ,
256264}
257265
258266impl Default for WorkspaceDepsBuilder {
259267 fn default ( ) -> Self {
260268 Self {
261269 formatter : TomlFormatter :: new ( ) ,
262270 deps : Vec :: new ( ) ,
271+ sort_dependencies : true ,
263272 }
264273 }
265274}
@@ -270,6 +279,13 @@ impl WorkspaceDepsBuilder {
270279 Self :: default ( )
271280 }
272281
282+ /// Set whether to sort dependencies alphabetically (default: true)
283+ pub fn with_dependency_sort ( mut self , sort : bool ) -> Self {
284+ self . sort_dependencies = sort;
285+ self . formatter . sort_dependencies = sort;
286+ self
287+ }
288+
273289 /// Add dependency
274290 pub fn add ( & mut self , name : & str , value : & str ) -> & mut Self {
275291 self . deps . push ( ( name. to_string ( ) , value. to_string ( ) , None ) ) ;
@@ -302,11 +318,15 @@ impl WorkspaceDepsBuilder {
302318 pub fn build ( & self ) -> RailResult < String > {
303319 let mut content = String :: from ( "\n [workspace.dependencies]\n " ) ;
304320
305- // Sort dependencies
306- let mut sorted_deps = self . deps . clone ( ) ;
307- sorted_deps. sort_by ( |a, b| a. 0 . cmp ( & b. 0 ) ) ;
321+ let deps_to_write = if self . sort_dependencies {
322+ let mut sorted = self . deps . clone ( ) ;
323+ sorted. sort_by ( |a, b| a. 0 . cmp ( & b. 0 ) ) ;
324+ sorted
325+ } else {
326+ self . deps . clone ( )
327+ } ;
308328
309- for ( name, value, comment) in sorted_deps {
329+ for ( name, value, comment) in deps_to_write {
310330 if let Some ( c) = comment {
311331 content. push_str ( & format ! ( "{} = {} # {}\n " , name, value, c) ) ;
312332 } else {
0 commit comments