pub struct PathManager<'a> { /* private fields */ }Expand description
A safe interface to the path handling features.
This struct is constructed from the three path handling features, MakePath, MapPath, and FreePath, and exposes them as one safe interface.
Please take a look at the module documentation for a usage example.
Implementations§
Source§impl<'a> PathManager<'a>
impl<'a> PathManager<'a>
Sourcepub fn new(make: MakePath<'a>, map: MapPath<'a>, free: FreePath<'a>) -> Self
pub fn new(make: MakePath<'a>, map: MapPath<'a>, free: FreePath<'a>) -> Self
Create a new path manager from the three path handling features.
Sourcepub fn allocate_path(
&mut self,
relative_path: &Path,
) -> Result<(ManagedPath<'a>, ManagedStr<'a>), StateErr>
pub fn allocate_path( &mut self, relative_path: &Path, ) -> Result<(ManagedPath<'a>, ManagedStr<'a>), StateErr>
Allocate a new path.
This function maps the given relative file path to an absolute file path as well as an abstract file path. The absolute file path can be used to access the new file and the abstract file path is used to reference it in the state of the plugin. Storing the absolute file path in the plugin state will not work since it might have changed when the state is restored.
The relative file path will be the suffix of the absolute file path and will be contained in a namespace unique to the plugin instance. This means that allocations of the same relative path by different plugin instances will not collide. Apart from that, you can not make any other assumptions about the absolute and abstract file paths.
An abstract file path that has been read from the plugin state can be mapped back to an absolute file path with the deabstract_path method.
Sourcepub fn deabstract_path(
&mut self,
path: &str,
) -> Result<ManagedPath<'a>, StateErr>
pub fn deabstract_path( &mut self, path: &str, ) -> Result<ManagedPath<'a>, StateErr>
Map an abstract file path back to an absolute one.
After reading an abstract file path from the state, you have to map it back to an absolute file path in order to read the file. This is what this method does.