Skip to main content

encode_workspace_path

Function encode_workspace_path 

Source
pub fn encode_workspace_path(path: &Utf8Path) -> String
Expand description

Encodes a workspace path into a directory-safe string.

The encoding is bijective (reversible) and produces valid directory names on all platforms. The encoding scheme uses underscore as an escape character:

  • _ → __ (escape underscore first)
  • / → _s (Unix path separator)
  • \ → _b (Windows path separator)
  • : → _c (Windows drive letter separator)
  • * → _a (asterisk, invalid on Windows)
  • " → _q (double quote, invalid on Windows)
  • < → _l (less than, invalid on Windows)
  • > → _g (greater than, invalid on Windows)
  • | → _p (pipe, invalid on Windows)
  • ? → _m (question mark, invalid on Windows)

If the encoded path exceeds 96 bytes, it is truncated at a valid UTF-8 boundary and an 8-character hash suffix is appended to maintain uniqueness.

§Examples

  • /home/rain/dev/nextest → _shome_srain_sdev_snextest
  • C:\Users\rain\dev → C_c_bUsers_brain_bdev
  • /path_with_underscore → _spath__with__underscore
  • /weird*path? → _sweird_apath_m