rust/utils: Improve TemporaryDirectory APIs

Rename the previous "default" `new` constructor [1] to `with_prefix` and
add a new default `new` constructor that takes no argument is therefore
easier to use.

In addition, improve the overall documentation, add more tests, and
examples to the code.

[1] https://doc.rust-lang.org/nomicon/constructors.html
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2024-09-04 10:57:10 +00:00
committed by Steffen Eiden
parent 2f3c189fda
commit 079ae1e24d
2 changed files with 69 additions and 16 deletions
+2 -2
View File
@@ -246,7 +246,7 @@ mod tests {
#[test]
fn test_sysfs_write_i32() {
let temp_dir =
TemporaryDirectory::new("pvtests").expect("creating a temporary directory should work");
TemporaryDirectory::new().expect("creating a temporary directory should work");
let test_path = temp_dir.path().join("test");
let test_path = test_path.as_os_str().to_str().expect("should work");
let mut file = File::create(test_path).unwrap();
@@ -264,7 +264,7 @@ mod tests {
#[test]
fn test_lockfile() {
let temp_dir =
TemporaryDirectory::new("pvtests").expect("creating a temporary directory should work");
TemporaryDirectory::new().expect("creating a temporary directory should work");
let file_path = temp_dir.path().join("my.lock");
let file_path_str = file_path.to_str().expect("should work");