blob: 5d37c318e106f5cfd711295b1dcd87e638be2011 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//! Utilities for manipulating paths.
use std::path::{Path, PathBuf};
pub trait PathBufExt {
/// Joins `self` with `path`, returning `self` unmodified if `path` is empty.
///
/// Takes ownership of `self`.
fn attach<P: AsRef<Path>>(self, path: P) -> PathBuf;
}
impl PathBufExt for PathBuf {
fn attach<P: AsRef<Path>>(mut self, path: P) -> PathBuf {
let path: &Path = path.as_ref();
if path.components().count() > 0 {
self.push(path)
}
self
}
}