[−][src]Struct grep_printer::PrinterPath
A simple encapsulation of a file path used by a printer.
This represents any transforms that we might want to perform on the path, such as converting it to valid UTF-8 and/or replacing its separator with something else. This allows us to amortize work if we are printing the file path for every match.
In the common case, no transformation is needed, which lets us avoid the
allocation. Typically, only Windows requires a transform, since we can't
access the raw bytes of a path directly and first need to lossily convert
to UTF-8. Windows is also typically where the path separator replacement
is used, e.g., in cygwin environments to use /
instead of \
.
Users of this type are expected to construct it from a normal Path
found in the standard library. It can then be written to any io::Write
implementation using the as_bytes
method. This achieves platform
portability with a small cost: on Windows, paths that are not valid UTF-16
will not roundtrip correctly.
Implementations
impl<'a> PrinterPath<'a>
[src]
pub fn new(path: &'a Path) -> PrinterPath<'a>
[src]
Create a new path suitable for printing.
pub fn with_separator(path: &'a Path, sep: Option<u8>) -> PrinterPath<'a>
[src]
Create a new printer path from the given path which can be efficiently written to a writer without allocation.
If the given separator is present, then any separators in path
are
replaced with it.
pub fn as_bytes(&self) -> &[u8]
[src]
Return the raw bytes for this path.
Trait Implementations
impl<'a> Clone for PrinterPath<'a>
[src]
fn clone(&self) -> PrinterPath<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Debug for PrinterPath<'a>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for PrinterPath<'a>
impl<'a> Send for PrinterPath<'a>
impl<'a> Sync for PrinterPath<'a>
impl<'a> Unpin for PrinterPath<'a>
impl<'a> UnwindSafe for PrinterPath<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,