pub struct Path<'a>(/* private fields */);
Expand description
Represents a (borrowed) path to file.
Neotron OS uses the following format for file paths:
<drive>:/[<directory>/]...<filename>.<extension>
Unlike on MS-DOS, the drive
specifier portion is not limited to a single
ASCII letter and can be any UTF-8 string that does not contain :
or /
.
Typically drives will look like DEV:
or HD0:
, but that’s not enforced
here.
Paths are a sub-set of UTF-8 strings in this API, but be aware that not all
filesystems support all Unicode characters. In particular FAT16 and FAT32
volumes are likely to be limited to only A-Z
, a-z
, 0-9
and
$%-_@~\
!(){}^#&`. This API will expressly disallow UTF-8 codepoints below
32 (i.e. C0 control characters) to avoid confusion, but non-ASCII
code-points are accepted.
Paths are case-preserving but file operations may not be case-sensitive (depending on the filesystem you are accessing). Paths may contain spaces (but your filesystem may not support that).
Here are some examples of valid paths:
# relative to the Current Directory
Documents/2023/June/Sales in €.xls
# a file on drive HD0
HD0:/MYDOCU~1/SALES.TXT
# a directory on drive SD0
SD0:/MYDOCU~1/
# a file on drive SD0, with no file extension
SD0:/BOOTLDR
Files and Directories generally have distinct APIs, so a directory without a
trailing /
is likely to be accepted. A file path with a trailing /
won’t
be accepted.
Implementations§
Source§impl<'a> Path<'a>
impl<'a> Path<'a>
Sourcepub const PATH_SEP: char = '/'
pub const PATH_SEP: char = '/'
The character that separates one directory name from another directory name.
Sourcepub const DRIVE_SEP: char = ':'
pub const DRIVE_SEP: char = ':'
The character that separates drive specifiers from directories.
Sourcepub fn new(path_str: &'a str) -> Result<Path<'a>, Error>
pub fn new(path_str: &'a str) -> Result<Path<'a>, Error>
Create a path from a string.
If the given string is not a valid path, an Err
is returned.
Sourcepub fn is_absolute_path(&self) -> bool
pub fn is_absolute_path(&self) -> bool
Is this an absolute path?
Absolute paths have drive specifiers. Relative paths do not.
Sourcepub fn drive_specifier(&self) -> Option<&str>
pub fn drive_specifier(&self) -> Option<&str>
Get the drive specifier for this path.
- A path like
DS0:/FOO/BAR.TXT
has a drive specifier ofDS0
. - A path like
BAR.TXT
has no drive specifier.
Sourcepub fn drive_path(&self) -> Option<&str>
pub fn drive_path(&self) -> Option<&str>
Get the drive path portion.
That is, everything after the directory specifier.
Sourcepub fn directory(&self) -> Option<&str>
pub fn directory(&self) -> Option<&str>
Get the directory portion of this path.
- A path like
DS0:/FOO/BAR.TXT
has a directory portion of/FOO
. - A path like
DS0:/FOO/BAR/
has a directory portion of/FOO/BAR
. - A path like
BAR.TXT
has no directory portion.
Sourcepub fn filename(&self) -> Option<&str>
pub fn filename(&self) -> Option<&str>
Get the filename portion of this path. This filename will include the file extension, if any.
- A path like
DS0:/FOO/BAR.TXT
has a filename portion of/BAR.TXT
. - A path like
DS0:/FOO
has a filename portion of/FOO
. - A path like
DS0:/FOO/
has no filename portion (so it’s important directories have a trailing/
)