Creating temporary directory doesnt work

hello all,

i am trying to create a temporary directory like so:

                let uuid = Uuid::new_v4().to_string();
                let tmpdirname = TempDir::new(&uuid);
                fs::create_dir(tmpdirname);
                    // copy files to temporary folder
                    for file in WalkDir::new("/tmp") {
                        // TODO:
                    }

however, this returns the error:

error[E0277]: the trait bound `Result<TempDir, std::io::Error>: AsRef<Path>` is not satisfied
    --> src/main.rs:30:32
     |
30   |                 fs::create_dir(tmpdirname);
     |                 -------------- ^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Result<TempDir, std::io::Error>`
     |                 |
     |                 required by a bound introduced by this call
     |
note: required by a bound in `create_dir`

As i am stilllearning rust, this doesnt make much sense to me. neither does the rustc --explaination that it shows me. i got this from a tutorial so i assume this is correct?

in the end i am trying to create a temporary directory, copy files and folders to it, execute a batch script that builds an msi, and then return this msi :slight_smile:

create_dir returns a Result, you have to handle it in some way before using it.

https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html

And tempdir already creates the directory

3 Likes

thank you :slight_smile: that info got me further :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.