harbor run -t openthoughts/tasktrove-exp-rpt-stack-rust-v2-stack-rust-1965harbor download openthoughts/tasktrove-exp-rpt-stack-rust-v2-stack-rust-1965Task Description: Implement the Path Struct Functionality
Implement the Path struct functionality for handling POSIX file paths in Rust. The Path struct already has several methods defined in the provided code, but the implementation is incomplete and needs to accommodate the following requirements:
Constructor Methods:
new method to create a Path from a byte vector or string. This method should panic if the provided vector contains a NUL byte.new_opt method to create a Path from a byte vector or string, returning None if the provided vector contains a NUL byte.Path Manipulation Methods:
push method that appends an additional path component (given as a byte vector) to the current path. Ensure the final path remains valid by normalizing it.set_filename method to change the last component of the Path to the specified filename, handling special cases for .. and ensuring normalization.pop method to remove the last component of the path, returning true if successful, and false if the path cannot be modified (like popping the root path).Path Component Accessor Methods:
filename method to return the last component of the path or None if the path is empty or represents . or ...dirname method to return the path representing everything except the last component, normalizing as needed.components method to provide an iterator yielding the components of the path as byte slices.Normalization:
Path struct to normalize the byte vector representation of a path by removing unnecessary components as per POSIX path rules, ensuring no empty components or unnecessary . or .. components remain.Utility Methods:
is_absolute method to check whether the path is absolute (begins with a /).join method to concatenate another path component properly, maintaining the integrity of the original path.Place your implementation in the /app/ directory under the Path struct definition and ensure it adheres to the Rust conventions and code style present in the provided code.
Pass the existing unit tests already defined in the code to confirm the functionality of the implemented methods.