chipsenkbeil / typed-path

Provides typed variants of Path and PathBuf for Unix and Windows
38 stars 6 forks source link

Clone is not available for PathBuf<T> #5

Closed parasyte closed 1 year ago

parasyte commented 1 year ago

WindowsPathBuf and UnixPathBuf type aliases do not implement Clone due to missing trait bound requirements.

UnixEncoding and WindowsEncoding must implement Clone to satisfy the T: Clone bound in:

impl<T> Clone for PathBuf<T>
where
    T: for<'enc> Encoding<'enc> + Clone,

Minimal test case:

use typed_path::NativePathBuf;

fn main() {
    let path1 = NativePathBuf::from("hello.txt");
    let path2 = path1.clone();

    println!("{path1:?}, {path2:?}");
}

Compile error:

error[E0599]: the method `clone` exists for struct `PathBuf<WindowsEncoding>`, but its trait bounds were not satisfied
  --> src\main.rs:5:23
   |
5  |     let path2 = path1.clone();
   |                       ^^^^^ method cannot be called on `PathBuf<WindowsEncoding>` due to unsatisfied trait bounds
   |
  ::: C:\Users\jay\.cargo\registry\src\github.com-1ecc6299db9ec823\typed-path-0.2.1\src\common\non_utf8\pathbuf.rs:61:1
   |
61 | pub struct PathBuf<T>
   | --------------------- doesn't satisfy `typed_path::PathBuf<WindowsEncoding>: Clone`
   |
  ::: C:\Users\jay\.cargo\registry\src\github.com-1ecc6299db9ec823\typed-path-0.2.1\src\windows\non_utf8.rs:19:1
   |
19 | pub struct WindowsEncoding;
   | -------------------------- doesn't satisfy `WindowsEncoding: Clone`
   |
   = note: the following trait bounds were not satisfied:
           `WindowsEncoding: Clone`
           which is required by `typed_path::PathBuf<WindowsEncoding>: Clone`
chipsenkbeil commented 1 year ago

@parasyte can you try this with the new 0.3 release? I updated the code to be more relaxed in the clone and debug requirements, so this should make it where you can leverage clone like normal.

parasyte commented 1 year ago

Thanks for quickly addressing this! It looks like this is no longer blocking me.