@@ -25,6 +25,25 @@ impl RecursiveMode {
2525 }
2626}
2727
28+ /// Controls how path separators are represented in emitted event paths on Windows.
29+ ///
30+ /// This applies to [`ReadDirectoryChangesWatcher`](crate::ReadDirectoryChangesWatcher).
31+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Debug , Hash , Default ) ]
32+ pub enum WindowsPathSeparatorStyle {
33+ /// Infer separator style from each watched input path.
34+ ///
35+ /// For example, watching `C:/tmp` yields paths with `/`, while watching `C:\tmp`
36+ /// yields paths with `\`.
37+ #[ default]
38+ Auto ,
39+
40+ /// Always use `/` in emitted event paths.
41+ Slash ,
42+
43+ /// Always use `\` in emitted event paths.
44+ Backslash ,
45+ }
46+
2847/// Watcher Backend configuration
2948///
3049/// This contains multiple settings that may relate to only one specific backend,
@@ -51,6 +70,9 @@ pub struct Config {
5170
5271 /// See [Config::with_event_kinds]
5372 event_kinds : EventKindMask ,
73+
74+ /// See [Config::with_windows_path_separator_style]
75+ windows_path_separator_style : WindowsPathSeparatorStyle ,
5476}
5577
5678impl Config {
@@ -155,6 +177,24 @@ impl Config {
155177 pub fn event_kinds ( & self ) -> EventKindMask {
156178 self . event_kinds
157179 }
180+
181+ /// For the [`ReadDirectoryChangesWatcher`](crate::ReadDirectoryChangesWatcher) backend.
182+ ///
183+ /// Controls path separator normalization for emitted event paths on Windows.
184+ ///
185+ /// The default is [`WindowsPathSeparatorStyle::Auto`], which preserves the
186+ /// separator style implied by each watched input path.
187+ ///
188+ /// This can't be changed during runtime.
189+ pub fn with_windows_path_separator_style ( mut self , style : WindowsPathSeparatorStyle ) -> Self {
190+ self . windows_path_separator_style = style;
191+ self
192+ }
193+
194+ /// Returns current setting.
195+ pub fn windows_path_separator_style ( & self ) -> WindowsPathSeparatorStyle {
196+ self . windows_path_separator_style
197+ }
158198}
159199
160200impl Default for Config {
@@ -164,6 +204,7 @@ impl Default for Config {
164204 compare_contents : false ,
165205 follow_symlinks : true ,
166206 event_kinds : EventKindMask :: ALL ,
207+ windows_path_separator_style : WindowsPathSeparatorStyle :: Auto ,
167208 }
168209 }
169210}
@@ -279,4 +320,23 @@ mod tests {
279320 assert_eq ! ( EventKindMask :: default ( ) , Config :: default ( ) . event_kinds( ) ) ;
280321 assert_eq ! ( EventKindMask :: default ( ) , EventKindMask :: ALL ) ;
281322 }
323+
324+ #[ test]
325+ fn config_default_windows_separator_style_is_auto ( ) {
326+ let config = Config :: default ( ) ;
327+ assert_eq ! (
328+ config. windows_path_separator_style( ) ,
329+ WindowsPathSeparatorStyle :: Auto
330+ ) ;
331+ }
332+
333+ #[ test]
334+ fn config_with_windows_separator_style ( ) {
335+ let config =
336+ Config :: default ( ) . with_windows_path_separator_style ( WindowsPathSeparatorStyle :: Slash ) ;
337+ assert_eq ! (
338+ config. windows_path_separator_style( ) ,
339+ WindowsPathSeparatorStyle :: Slash
340+ ) ;
341+ }
282342}
0 commit comments