Calling Utf8Path::try_from on an std::path::Path fails with "the size for values of type [u8] cannot be known at compilation time".
Example code:
use camino::Utf8Path;
use std::path::Path;
fn main() {
let path1 = Path::new("/test");
// This works:
let path2 = Utf8Path::from_path(path1).unwrap();
// But this fails with "the size for values of type `[u8]` cannot be known at compilation time"
let path3 = Utf8Path::try_from(path1).unwrap();
}
Full error output:
$ cargo build
Compiling camino-test v0.1.0 (/home/nicholasbishop/tmp/camino-test)
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/main.rs:9:17
|
9 | let path3 = Utf8Path::try_from(path1).unwrap();
| ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `Utf8Path`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `Utf8Path`
--> /home/nicholasbishop/.cargo/registry/src/index.crates.io-6f17d22bba15001f/camino-1.1.6/src/lib.rs:545:12
|
545 | pub struct Utf8Path(Path);
| ^^^^^^^^
note: required by a bound in `try_from`
--> /home/nicholasbishop/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:638:23
|
638 | pub trait TryFrom<T>: Sized {
| ^^^^^ required by this bound in `TryFrom::try_from`
...
645 | fn try_from(value: T) -> Result<Self, Self::Error>;
| -------- required by a bound in this associated function
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/main.rs:9:17
|
9 | let path3 = Utf8Path::try_from(path1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `Utf8Path`, the trait `Sized` is not implemented for `[u8]`
= help: the trait `TryFrom<&'a Path>` is implemented for `&'a Utf8Path`
note: required because it appears within the type `Utf8Path`
--> /home/nicholasbishop/.cargo/registry/src/index.crates.io-6f17d22bba15001f/camino-1.1.6/src/lib.rs:545:12
|
545 | pub struct Utf8Path(Path);
| ^^^^^^^^
= note: required for `Utf8Path` to implement `TryFrom<_>`
error[E0277]: the trait bound `Utf8Path: From<&Path>` is not satisfied
--> src/main.rs:9:36
|
9 | let path3 = Utf8Path::try_from(path1).unwrap();
| ------------------ ^^^^^ the trait `From<&Path>` is not implemented for `Utf8Path`
| |
| required by a bound introduced by this call
|
= help: the trait `From<&'a str>` is implemented for `&'a Utf8Path`
= note: required for `&Path` to implement `Into<Utf8Path>`
= note: required for `Utf8Path` to implement `TryFrom<&Path>`
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/main.rs:9:36
|
9 | let path3 = Utf8Path::try_from(path1).unwrap();
| ------------------ ^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: within `Utf8Path`, the trait `Sized` is not implemented for `[u8]`
= help: the trait `TryFrom<&'a Path>` is implemented for `&'a Utf8Path`
note: required because it appears within the type `Utf8Path`
--> /home/nicholasbishop/.cargo/registry/src/index.crates.io-6f17d22bba15001f/camino-1.1.6/src/lib.rs:545:12
|
545 | pub struct Utf8Path(Path);
| ^^^^^^^^
= note: required for `&Path` to implement `Into<Utf8Path>`
= note: required for `Utf8Path` to implement `TryFrom<&Path>`
error[E0599]: the method `unwrap` exists for enum `Result<Utf8Path, Infallible>`, but its trait bounds were not satisfied
--> src/main.rs:9:43
|
9 | let path3 = Utf8Path::try_from(path1).unwrap();
| ^^^^^^ method cannot be called on `Result<Utf8Path, Infallible>` due to unsatisfied trait bounds
|
::: /home/nicholasbishop/.cargo/registry/src/index.crates.io-6f17d22bba15001f/camino-1.1.6/src/lib.rs:545:1
|
545 | pub struct Utf8Path(Path);
| ------------------- doesn't satisfy `Utf8Path: Sized`
|
= note: the following trait bounds were not satisfied:
`Utf8Path: Sized`
error[E0277]: the trait bound `Utf8Path: From<&Path>` is not satisfied
--> src/main.rs:9:17
|
9 | let path3 = Utf8Path::try_from(path1).unwrap();
| ^^^^^^^^^^^^^^^^^^ the trait `From<&Path>` is not implemented for `Utf8Path`
|
= help: the trait `From<&'a str>` is implemented for `&'a Utf8Path`
= note: required for `&Path` to implement `Into<Utf8Path>`
= note: required for `Utf8Path` to implement `TryFrom<&Path>`
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
Calling
Utf8Path::try_from
on anstd::path::Path
fails with "the size for values of type[u8]
cannot be known at compilation time".Example code:
Full error output: