pub struct FilePath(/* private fields */);Expand description
A validated virtual filesystem path.
FilePath ensures paths use Unix-style conventions on all platforms:
- Must start with ‘/’ (absolute paths only)
- Free of parent directory references (‘..’)
- Use forward slashes as separators
This is intentional: VFS paths are platform-independent and always use Unix conventions, even on Windows. This enables consistent path handling across development machines and CI environments.
§Examples
use mcp_execution_files::FilePath;
let path = FilePath::new("/mcp-tools/servers/test/file.ts").unwrap();
assert_eq!(path.as_str(), "/mcp-tools/servers/test/file.ts");use mcp_execution_files::FilePath;
// Invalid paths are rejected
assert!(FilePath::new("relative/path").is_err());
assert!(FilePath::new("/parent/../escape").is_err());On Windows, Unix-style paths like “/mcp-tools/servers/test” are accepted (not Windows paths like “C:\mcp-tools\servers\test”).
Implementations§
Source§impl FilePath
impl FilePath
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
Creates a new FilePath from a path-like type.
The path must be absolute (start with ‘/’) and must not contain parent directory references (‘..’).
FilePath uses Unix-style path conventions on all platforms, ensuring
consistent behavior on Linux, macOS, and Windows. Paths are validated
using string-based checks rather than platform-specific Path::is_absolute(),
which enables cross-platform compatibility.
§Errors
Returns FilesError::PathNotAbsolute if the path does not start with ‘/’.
Returns FilesError::InvalidPathComponent if the path contains ‘..’.
Returns FilesError::InvalidPath if the path is empty or not UTF-8 valid.
§Examples
use mcp_execution_files::FilePath;
let path = FilePath::new("/mcp-tools/test.ts")?;
assert_eq!(path.as_str(), "/mcp-tools/test.ts");
// Works on all platforms (Unix-style paths)
let path = FilePath::new("/mcp-tools/servers/test/manifest.json")?;Sourcepub fn as_path(&self) -> &Path
pub fn as_path(&self) -> &Path
Returns the path as a Path reference.
§Examples
use mcp_execution_files::FilePath;
let vfs_path = FilePath::new("/test.ts")?;
let path = vfs_path.as_path();
assert_eq!(path.to_str(), Some("/test.ts"));Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the path as a string slice.
§Examples
use mcp_execution_files::FilePath;
let path = FilePath::new("/mcp-tools/file.ts")?;
assert_eq!(path.as_str(), "/mcp-tools/file.ts");Sourcepub fn parent(&self) -> Option<Self>
pub fn parent(&self) -> Option<Self>
Returns the parent directory of this path.
Returns None if this is the root path.
§Examples
use mcp_execution_files::FilePath;
let path = FilePath::new("/mcp-tools/servers/test.ts")?;
let parent = path.parent().unwrap();
assert_eq!(parent.as_str(), "/mcp-tools/servers");Sourcepub fn is_dir_path(&self) -> bool
pub fn is_dir_path(&self) -> bool
Checks if this path is a directory path.
A path is considered a directory if it does not have a file extension.
§Examples
use mcp_execution_files::FilePath;
let dir = FilePath::new("/mcp-tools/servers")?;
assert!(dir.is_dir_path());
let file = FilePath::new("/mcp-tools/manifest.json")?;
assert!(!file.is_dir_path());Trait Implementations§
impl Eq for FilePath
impl StructuralPartialEq for FilePath
Auto Trait Implementations§
impl Freeze for FilePath
impl RefUnwindSafe for FilePath
impl Send for FilePath
impl Sync for FilePath
impl Unpin for FilePath
impl UnwindSafe for FilePath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.