Trait typed_path::TryAsRef
source · pub trait TryAsRef<T: ?Sized> {
// Required method
fn try_as_ref(&self) -> Option<&T>;
}
Expand description
Interface to try to perform a cheap reference-to-reference conversion.
Required Methods§
fn try_as_ref(&self) -> Option<&T>
Implementations on Foreign Types§
source§impl<T> TryAsRef<Path<T>> for Pathwhere
T: for<'enc> Encoding<'enc>,
impl<T> TryAsRef<Path<T>> for Pathwhere T: for<'enc> Encoding<'enc>,
source§fn try_as_ref(&self) -> Option<&Path<T>>
fn try_as_ref(&self) -> Option<&Path<T>>
Attempts to convert a std::path::Path
into a Path
, returning a result containing
the new path when successful
Examples
use std::path::Path;
use typed_path::{TryAsRef, UnixPath};
let std_path = Path::new("/path/to/file.txt");
let unix_path: &UnixPath = std_path.try_as_ref().unwrap();