/// Returns this path relative to the file it was delcared in, if any.
/// Returns the original if this path was not declared in a file or if the
/// path has a root.
///
/// # Example
///
/// ```rust
/// use std::path::Path;
///
/// use figment::{Figment, value::magic::RelativePathBuf, Jail};
/// use figment::providers::{Env, Format, Toml};
///
/// #[derive(Debug, PartialEq, serde::Deserialize)]
/// struct Config {
///     path: RelativePathBuf,
/// }
///
/// Jail::expect_with(|jail| {
///     jail.create_file("Config.toml", r#"path = "hello.html""#)?;
///     let c: Config = Figment::from(Toml::file("Config.toml")).extract()?;
///     assert_eq!(c.path.relative(), jail.directory().join("hello.html"));
///
///     jail.set_env("PATH", r#"hello.html"#);
///     let c: Config = Figment::from(Env::raw().only(&["PATH"])).extract()?;
///     assert_eq!(c.path.relative(), Path::new("hello.html"));
///
///     Ok(())
/// });
/// ```
Returns this path relative to the file it was delcared in, if any.
Returns the original if this path was not declared in a file or if the
path has a root.
Returns this path relative to the file it was delcared in if any . Returns the original if this path was not declared in a file or if the path has a root .
pub fn relative(&self) -> PathBuf {
        if self.original().has_root() {
            return self.original().into();
        }
        self.metadata_path()
            .and_then(|root| match root.is_dir() {
                true => Some(root),
                false => root.parent(),
            })
            .map(|root| root.join(self.original()))
            .unwrap_or_else(|| self.original().into())
    }
pub fn relative ( & self ) -> PathBuf { if self . original ( ) . has_root ( ) { return self . original ( ) . into ( ) ; } self . metadata_path ( ) . and_then ( | root | match root . is_dir ( ) { true => Some ( root ) , false => root . parent ( ) , } ) . map ( | root | root . join ( self . original ( ) ) ) . unwrap_or_else ( | | self . original ( ) . into ( ) ) }
Returns this path relative to the file it was delcared in, if any.
Returns this path relative to the file it was delcared in if any .
&self
example
```rust
use std::path::Path.

use figment::{Figment, value::magic::RelativePathBuf, Jail};
use figment::providers::{Env, Format, Toml}.
` ` ` rust use std :: path :: Path . use figment :: { Figment value :: magic :: RelativePathBuf Jail } ; use figment :: providers :: { Env Format Toml } .
[derive(debug, partialeq, serde::deserialize)]
struct Config {
path: RelativePathBuf,
}

:expect_with(|jail| {
jail.create_file("Config.toml", r#"path = "hello.html""#)?;
let c: Config = Figment::from(Toml::file("Config.toml")).extract()?;
assert_eq!(c.path.relative(), jail.directory().join("hello.html")).

jail.set_env("PATH", r#"hello.html"#);
let c: Config = Figment::from(Env::raw().only(&["PATH"])).extract()?;
assert_eq!(c.path.relative(), Path::new("hello.html")).


struct Config { path : RelativePathBuf } : expect_with ( |jail| { jail . create_file ( " Config . toml " r# " path = " hello . html " " # ) ? ; let c : Config = Figment :: from ( Toml :: file ( " Config . toml " )) . extract () ? ; assert_eq! ( c . path . relative () jail . directory () . join ( " hello . html " )) . jail . set_env ( " PATH " r# " hello . html " # ) ; let c : Config = Figment :: from ( Env :: raw () . only ( & [ " PATH " ] )) . extract () ? ; assert_eq! ( c . path . relative () Path :: new ( " hello . html " )) .