Remove separator! macro and make path! handle relative paths (#32527)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-06-13 00:32:29 -06:00 committed by GitHub
parent babf846ef9
commit 9cc82212b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 302 additions and 343 deletions

View file

@ -30,7 +30,7 @@ use unicase::UniCase;
pub use take_until::*;
#[cfg(any(test, feature = "test-support"))]
pub use util_macros::{line_endings, separator, uri};
pub use util_macros::{line_endings, path, uri};
#[macro_export]
macro_rules! debug_panic {
@ -44,50 +44,6 @@ macro_rules! debug_panic {
};
}
/// A macro to add "C:" to the beginning of a path literal on Windows, and replace all
/// the separator from `/` to `\`.
/// But on non-Windows platforms, it will return the path literal as is.
///
/// # Examples
/// ```rust
/// use util::path;
///
/// let path = path!("/Users/user/file.txt");
/// #[cfg(target_os = "windows")]
/// assert_eq!(path, "C:\\Users\\user\\file.txt");
/// #[cfg(not(target_os = "windows"))]
/// assert_eq!(path, "/Users/user/file.txt");
/// ```
#[cfg(all(any(test, feature = "test-support"), target_os = "windows"))]
#[macro_export]
macro_rules! path {
($path:literal) => {
concat!("C:", util::separator!($path))
};
}
/// A macro to add "C:" to the beginning of a path literal on Windows, and replace all
/// the separator from `/` to `\`.
/// But on non-Windows platforms, it will return the path literal as is.
///
/// # Examples
/// ```rust
/// use util::path;
///
/// let path = path!("/Users/user/file.txt");
/// #[cfg(target_os = "windows")]
/// assert_eq!(path, "C:\\Users\\user\\file.txt");
/// #[cfg(not(target_os = "windows"))]
/// assert_eq!(path, "/Users/user/file.txt");
/// ```
#[cfg(all(any(test, feature = "test-support"), not(target_os = "windows")))]
#[macro_export]
macro_rules! path {
($path:literal) => {
$path
};
}
pub fn truncate(s: &str, max_chars: usize) -> &str {
match s.char_indices().nth(max_chars) {
None => s,