Lines Matching +full:is +full:- +full:path +full:- +full:inside
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
13 use std::path::{self, Path, PathBuf};
24 /// destructor is run.
28 /// See [the resource leaking][resource-leaking] docs on `TempDir`.
32 /// If the directory can not be created, `Err` is returned.
46 /// # fn run() -> Result<(), io::Error> {
47 /// // Create a directory inside of `std::env::temp_dir()`
50 /// let file_path = dir.path().join("my-temporary-note.txt");
63 /// [resource-leaking]: struct.TempDir.html#resource-leaking
64 pub fn tempdir() -> io::Result<TempDir> { in tempdir()
73 /// destructor is run.
77 /// See [the resource leaking][resource-leaking] docs on `TempDir`.
81 /// If the directory can not be created, `Err` is returned.
95 /// # fn run() -> Result<(), io::Error> {
96 /// // Create a directory inside of `std::env::temp_dir()`,
99 /// let file_path = dir.path().join("my-temporary-note.txt");
112 /// [resource-leaking]: struct.TempDir.html#resource-leaking
113 pub fn tempdir_in<P: AsRef<Path>>(dir: P) -> io::Result<TempDir> { in tempdir_in()
117 /// A directory in the filesystem that is automatically deleted when
121 /// is deleted once it goes out of scope. At construction, the
130 /// standard [`std::fs`] file system operations on its [`Path`],
131 /// which can be retrieved with [`TempDir::path()`]. Once the `TempDir`
132 /// value is dropped, the directory at the path will be deleted, along
133 /// with any files and directories it contains. It is your responsibility
135 /// inside the temporary directory once it has been deleted.
139 /// Various platform-specific conditions may cause `TempDir` to fail
141 /// handles (like [`File`] and [`ReadDir`]) to files inside the
146 /// Note that if the program exits before the `TempDir` destructor is
161 /// # fn run() -> Result<(), io::Error> {
162 /// // Create a directory inside of `std::env::temp_dir()`
176 /// # fn run() -> Result<(), io::Error> {
177 /// // Create a directory inside of `std::env::temp_dir()`,
184 /// [`File`]: http://doc.rust-lang.org/std/fs/struct.File.html
185 /// [`Path`]: http://doc.rust-lang.org/std/path/struct.Path.html
186 /// [`ReadDir`]: http://doc.rust-lang.org/std/fs/struct.ReadDir.html
190 /// [`TempDir::path()`]: struct.TempDir.html#method.path
192 /// [`std::env::temp_dir()`]: https://doc.rust-lang.org/std/env/fn.temp_dir.html
193 /// [`std::fs`]: http://doc.rust-lang.org/std/fs/index.html
194 /// [`std::process::exit()`]: http://doc.rust-lang.org/std/process/fn.exit.html
196 path: Box<Path>, field
200 /// Attempts to make a temporary directory inside of `env::temp_dir()`.
204 /// The directory and everything inside it will be automatically deleted
205 /// once the returned `TempDir` is destroyed.
209 /// If the directory can not be created, `Err` is returned.
219 /// # fn run() -> Result<(), io::Error> {
220 /// // Create a directory inside of `std::env::temp_dir()`
223 /// let file_path = tmp_dir.path().join("my-temporary-note.txt");
234 pub fn new() -> io::Result<TempDir> { in new()
238 /// Attempts to make a temporary directory inside of `dir`.
239 /// The directory and everything inside it will be automatically
240 /// deleted once the returned `TempDir` is destroyed.
244 /// If the directory can not be created, `Err` is returned.
254 /// # fn run() -> Result<(), io::Error> {
255 /// // Create a directory inside of the current directory
257 /// let file_path = tmp_dir.path().join("my-temporary-note.txt");
263 pub fn new_in<P: AsRef<Path>>(dir: P) -> io::Result<TempDir> { in new_in()
267 /// Accesses the [`Path`] to the temporary directory.
269 /// [`Path`]: http://doc.rust-lang.org/std/path/struct.Path.html
277 /// # fn run() -> Result<(), io::Error> {
282 /// tmp_path = tmp_dir.path().to_owned();
295 pub fn path(&self) -> &path::Path { in path() argument
296 self.path.as_ref() in path()
299 /// Persist the temporary directory to disk, returning the [`PathBuf`] where it is located.
305 /// [`PathBuf`]: http://doc.rust-lang.org/std/path/struct.PathBuf.html
314 /// # fn run() -> Result<(), io::Error> {
318 /// // getting the path where it is.
326 pub fn into_path(self) -> PathBuf { in into_path()
330 // replace this.path with an empty Box, since an empty Box does not in into_path()
332 mem::replace(&mut this.path, PathBuf::new().into_boxed_path()).into() in into_path()
348 /// [`std::io::Error`]: http://doc.rust-lang.org/std/io/struct.Error.html
358 /// # fn run() -> Result<(), io::Error> {
359 /// // Create a directory inside of `std::env::temp_dir()`.
361 /// let file_path = tmp_dir.path().join("my-temporary-note.txt");
375 pub fn close(mut self) -> io::Result<()> { in close()
376 let result = remove_dir_all(self.path()).with_err_path(|| self.path()); in close()
378 // Set self.path to empty Box to release the memory, since an empty in close()
380 self.path = PathBuf::new().into_boxed_path(); in close()
389 impl AsRef<Path> for TempDir {
390 fn as_ref(&self) -> &Path { in as_ref() argument
391 self.path() in as_ref()
396 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { in fmt()
398 .field("path", &self.path()) in fmt()
405 let _ = remove_dir_all(self.path()); in drop()
409 pub(crate) fn create(path: PathBuf) -> io::Result<TempDir> { in create()
410 fs::create_dir(&path) in create()
411 .with_err_path(|| &path) in create()
413 path: path.into_boxed_path(), in create()