Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PartialOrd and PartialEq for UTF-8 strings and FFI Strings #76189

Closed
wants to merge 1 commit into from
Closed

Implement PartialOrd and PartialEq for UTF-8 strings and FFI Strings #76189

wants to merge 1 commit into from

Commits on Sep 1, 2020

  1. Implement PartialOrd and PartialEq for UTF-8 strings and FFI Strings

    This PR adds many more `PartialEq` and `PartialOrd` implementations for
    `Path`, `PathBuf`, `OsStr`, `OsString`, and `Component`.
    
    The Rust Standard Library guarantees that these types are freely and
    cheaply constructable from UTF-8 `String` and `&str`, but comparing
    these types with `&str` literals is not ergonomic. One use case I'd like
    to enable is filtering out paths containing a "test" directory while
    walking a tree and inspecting the path with the `components()` iterator.
    
    Example:
    
    ```rust
    let is_test_source = relative_source
        .components()
        .any(|component| component.as_os_str() == OsStr::new("test"));
    ```
    
    New core trait impls:
    
    `OsString`:
    
    - `impl PartialEq<String> for OsString` and reflexive
    - `impl PartialEq<Cow<'_, str>> for OsString` and reflexive
    - `impl PartialEq<Box<str>> for OsString` and reflexive
    - `impl PartialEq<Rc<str>> for OsString` and reflexive
    - `impl PartialEq<Arc<str>> for OsString` and reflexive
    - `impl PartialOrd<String> for OsString` and reflexive
    - `impl PartialOrd<Cow<'_, str>> for OsString` and reflexive
    - `impl PartialOrd<Box<str>> for OsString` and reflexive
    - `impl PartialOrd<Rc<str>> for OsString` and reflexive
    - `impl PartialOrd<Arc<str>> for OsString` and reflexive
    
    `OsStr`:
    
    - `impl PartialEq<String> for OsStr` and reflexive
    - `impl PartialEq<Cow<'_, str>> for OsStr` and reflexive
    - `impl PartialEq<Box<str>> for OsStr` and reflexive
    - `impl PartialEq<Rc<str>> for OsStr` and reflexive
    - `impl PartialEq<Arc<str>> for OsStr` and reflexive
    - `impl PartialOrd<String> for OsStr` and reflexive
    - `impl PartialOrd<Cow<'_, str>> for OsStr` and reflexive
    - `impl PartialOrd<Box<str>> for OsStr` and reflexive
    - `impl PartialOrd<Rc<str>> for OsStr` and reflexive
    - `impl PartialOrd<Arc<str>> for OsStr` and reflexive
    
    `Component`:
    
    - `impl PartialEq<OsStr> for Component` and reflexive
    - `impl PartialEq<&'_ OsStr> for Component` and reflexive
    - `impl PartialEq<OsString> for Component` and reflexive
    - `impl PartialEq<Cow<'_, OsStr>> for Component` and reflexive
    - `impl PartialEq<Box<OsStr>> for Component` and reflexive
    - `impl PartialEq<Path> for Component` and reflexive
    - `impl PartialEq<&'_ Path> for Component` and reflexive
    - `impl PartialEq<PathBuf> for Component` and reflexive
    - `impl PartialEq<Cow<'_, Path>> for Component` and reflexive
    - `impl PartialEq<Box<Path>> for Component` and reflexive
    - `impl PartialEq<str> for Component` and reflexive
    - `impl PartialEq<String> for Component` and reflexive
    - `impl PartialEq<Cow<'_, str>> for Component` and reflexive
    - `impl PartialEq<Box<str>> for Component` and reflexive
    - `impl PartialEq<Rc<str>> for Component` and reflexive
    - `impl PartialEq<Arc<str>> for Component` and reflexive
    - `impl PartialEq<str> for Component` and reflexive
    - `impl PartialEq<String> for Component` and reflexive
    - `impl PartialEq<Cow<'_, str>> for Component` and reflexive
    - `impl PartialEq<Box<str>> for Component` and reflexive
    - `impl PartialEq<Rc<str>> for Component` and reflexive
    - `impl PartialEq<Arc<str>> for Component` and reflexive
    - `impl PartialOrd<OsStr> for Component` and reflexive
    - `impl PartialOrd<&'_ OsStr> for Component` and reflexive
    - `impl PartialOrd<OsString> for Component` and reflexive
    - `impl PartialOrd<Cow<'_, OsStr>> for Component` and reflexive
    - `impl PartialOrd<Box<OsStr>> for Component` and reflexive
    - `impl PartialOrd<Path> for Component` and reflexive
    - `impl PartialOrd<&'_ Path> for Component` and reflexive
    - `impl PartialOrd<PathBuf> for Component` and reflexive
    - `impl PartialOrd<Cow<'_, Path>> for Component` and reflexive
    - `impl PartialOrd<Box<Path>> for Component` and reflexive
    - `impl PartialOrd<str> for Component` and reflexive
    - `impl PartialOrd<String> for Component` and reflexive
    - `impl PartialOrd<Cow<'_, str>> for Component` and reflexive
    - `impl PartialOrd<Box<str>> for Component` and reflexive
    - `impl PartialOrd<Rc<str>> for Component` and reflexive
    - `impl PartialOrd<Arc<str>> for Component` and reflexive
    
    `PathBuf`:
    
    - `impl PartialEq<str> for PathBuf` and reflexive
    - `impl PartialEq<&'_ str> for PathBuf` and reflexive
    - `impl PartialEq<String> for PathBuf` and reflexive
    - `impl PartialEq<Cow<'_, str>> for PathBuf` and reflexive
    - `impl PartialEq<Box<str>> for PathBuf` and reflexive
    - `impl PartialEq<Rc<str>> for PathBuf` and reflexive
    - `impl PartialEq<Arc<str>> for PathBuf` and reflexive
    - `impl PartialOrd<str> for PathBuf` and reflexive
    - `impl PartialOrd<&'_ str> for PathBuf` and reflexive
    - `impl PartialOrd<String> for PathBuf` and reflexive
    - `impl PartialOrd<Cow<'_, str>> for PathBuf` and reflexive
    - `impl PartialOrd<Box<str>> for PathBuf` and reflexive
    - `impl PartialOrd<Rc<str>> for PathBuf` and reflexive
    - `impl PartialOrd<Arc<str>> for PathBuf` and reflexive
    
    `Path`:
    
    - `impl PartialEq<str> for Path` and reflexive
    - `impl PartialEq<&'_ str> for Path` and reflexive
    - `impl PartialEq<String> for Path` and reflexive
    - `impl PartialEq<Cow<'_, str>> for Path` and reflexive
    - `impl PartialEq<Box<str>> for Path` and reflexive
    - `impl PartialEq<Rc<str>> for Path` and reflexive
    - `impl PartialEq<Arc<str>> for Path` and reflexive
    - `impl PartialOrd<str> for Path` and reflexive
    - `impl PartialOrd<&'_ str> for Path` and reflexive
    - `impl PartialOrd<String> for Path` and reflexive
    - `impl PartialOrd<Cow<'_, str>> for Path` and reflexive
    - `impl PartialOrd<Box<str>> for Path` and reflexive
    - `impl PartialOrd<Rc<str>> for Path` and reflexive
    - `impl PartialOrd<Arc<str>> for Path` and reflexive
    
    Fixes #71700.
    lopopolo committed Sep 1, 2020
    Configuration menu
    Copy the full SHA
    c3b0393 View commit details
    Browse the repository at this point in the history