Trait UriExt

Source
pub trait UriExt: Sized + Sealed {
    // Required methods
    fn to_file_path(&self) -> Option<Cow<'_, Path>>;
    fn from_file_path<A: AsRef<Path>>(path: A) -> Option<Self>;
}
Expand description

Provide methods to lsp_types::Uri to fill blanks left by fluent_uri (the underlying type) especially when converting to and from file paths.

Required Methods§

Source

fn to_file_path(&self) -> Option<Cow<'_, Path>>

Assuming the URL is in the file scheme or similar, convert its path to an absolute std::path::Path.

Note: This does not actually check the URL’s scheme, and may give nonsensical results for other schemes. It is the user’s responsibility to check the URL’s scheme before calling this.

e.g. Uri("file:///etc/passwd") becomes PathBuf("/etc/passwd")

Source

fn from_file_path<A: AsRef<Path>>(path: A) -> Option<Self>

Convert a file path to a lsp_types::Uri.

Create a lsp_types::Uri from a file path.

Returns None if the file does not exist.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl UriExt for Uri

Source§

fn to_file_path(&self) -> Option<Cow<'_, Path>>

Source§

fn from_file_path<A: AsRef<Path>>(path: A) -> Option<Self>

Implementors§