pub struct PathResolver { /* private fields */ }
Expand description
A resolver that keeps relative paths on a stack for recursive include process.
§Examples
use plantuml_parser::PathResolver;
use std::path::PathBuf;
let resolver_0 = PathResolver::new("./dir-1/x1.puml");
assert_eq!(resolver_0.build()?, PathBuf::from("dir-1/x1.puml"));
assert_eq!(resolver_0.build_without_normalize()?, PathBuf::from("./dir-1/x1.puml"));
// For example, `./dir-1/x1.puml` includes `./dir-2/x2.puml`.
let mut resolver_0_0 = resolver_0.clone();
resolver_0_0.add("./dir-2/x2.puml".into());
assert_eq!(resolver_0_0.build()?, PathBuf::from("dir-1/dir-2/x2.puml"));
assert_eq!(resolver_0_0.build_without_normalize()?, PathBuf::from("./dir-1/dir-2/x2.puml"));
// For example, `./dir-1/x1.puml` includes `./dir-3/x3.puml`.
let mut resolver_0_1 = resolver_0.clone();
resolver_0_1.add("./dir-3/x3.puml".into());
assert_eq!(resolver_0_1.build()?, PathBuf::from("dir-1/dir-3/x3.puml"));
assert_eq!(resolver_0_1.build_without_normalize()?, PathBuf::from("./dir-1/dir-3/x3.puml"));
// For example, `./dir-1/dir-3/x3.puml` includes `../../dir-4/x4.puml`.
let mut resolver_0_1_0 = resolver_0_1.clone();
resolver_0_1_0.add("../../dir-4/x4.puml".into());
assert_eq!(resolver_0_1_0.build()?, PathBuf::from("dir-4/x4.puml"));
assert_eq!(resolver_0_1_0.build_without_normalize()?, PathBuf::from("./dir-1/dir-3/../../dir-4/x4.puml"));
Implementations§
Source§impl PathResolver
impl PathResolver
Sourcepub fn build(&self) -> Result<PathBuf, Error>
pub fn build(&self) -> Result<PathBuf, Error>
Returns the resolved normalized path. All PathBuf
s in the stack are treated as paths relative to the file.
§Examples
let mut resolver = PathResolver::new("dir-1/file-1");
assert_eq!(resolver.build()?, PathBuf::from("dir-1/file-1"));
resolver.add("../dir-2/file-2".into());
assert_eq!(resolver.build()?, PathBuf::from("dir-2/file-2"));
resolver.add("../dir-3/file-3".into());
assert_eq!(resolver.build()?, PathBuf::from("dir-3/file-3"));
Sourcepub fn build_without_normalize(&self) -> Result<PathBuf, Error>
pub fn build_without_normalize(&self) -> Result<PathBuf, Error>
Returns the resolved the path not normalized.
§Examples
let mut resolver = PathResolver::new("dir-1/file-1");
assert_eq!(
resolver.build_without_normalize()?,
PathBuf::from("dir-1/file-1")
);
resolver.add("../dir-2/file-2".into());
assert_eq!(
resolver.build_without_normalize()?,
PathBuf::from("dir-1/../dir-2/file-2")
);
resolver.add("../dir-3/file-3".into());
assert_eq!(
resolver.build_without_normalize()?,
PathBuf::from("dir-1/../dir-2/../dir-3/file-3")
);
Trait Implementations§
Source§impl Clone for PathResolver
impl Clone for PathResolver
Source§fn clone(&self) -> PathResolver
fn clone(&self) -> PathResolver
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for PathResolver
impl RefUnwindSafe for PathResolver
impl Send for PathResolver
impl Sync for PathResolver
impl Unpin for PathResolver
impl UnwindSafe for PathResolver
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
Mutably borrows from an owned value. Read more