@@ -100,8 +100,8 @@ pub fn unwrap_joinhandle_value<T>(value: T) -> T {
100
100
pub use tokio:: task:: JoinHandle ;
101
101
#[ cfg( feature = "tokio" ) ]
102
102
#[ inline]
103
- pub fn unwrap_joinhandle_value < T > ( value : Result < T , tokio :: task :: JoinError > ) -> T {
104
- value. unwrap ( )
103
+ pub fn unwrap_joinhandle_value < T > ( value : T ) -> T {
104
+ value
105
105
}
106
106
107
107
use tempfile:: NamedTempFile ;
@@ -110,19 +110,28 @@ use crate::errors::IoErrorExt;
110
110
111
111
#[ cfg( feature = "async-std" ) ]
112
112
#[ inline]
113
- pub async fn create_named_tempfile ( tmp_path : std:: path:: PathBuf ) -> crate :: Result < NamedTempFile > {
113
+ pub async fn create_named_tempfile (
114
+ tmp_path : std:: path:: PathBuf ,
115
+ ) -> Option < crate :: Result < NamedTempFile > > {
114
116
let cloned = tmp_path. clone ( ) ;
115
- spawn_blocking ( || NamedTempFile :: new_in ( tmp_path) )
116
- . await
117
- . with_context ( || format ! ( "Failed to create a temp file at {}" , cloned. display( ) ) )
117
+
118
+ Some (
119
+ spawn_blocking ( || NamedTempFile :: new_in ( tmp_path) )
120
+ . await
121
+ . with_context ( || format ! ( "Failed to create a temp file at {}" , cloned. display( ) ) ) ,
122
+ )
118
123
}
119
124
120
125
#[ cfg( feature = "tokio" ) ]
121
126
#[ inline]
122
- pub async fn create_named_tempfile ( tmp_path : std:: path:: PathBuf ) -> crate :: Result < NamedTempFile > {
127
+ pub async fn create_named_tempfile (
128
+ tmp_path : std:: path:: PathBuf ,
129
+ ) -> Option < crate :: Result < NamedTempFile > > {
123
130
let cloned = tmp_path. clone ( ) ;
124
- spawn_blocking ( || NamedTempFile :: new_in ( tmp_path) )
125
- . await
126
- . unwrap ( )
127
- . with_context ( || format ! ( "Failed to create a temp file at {}" , cloned. display( ) ) )
131
+ match spawn_blocking ( || NamedTempFile :: new_in ( tmp_path) ) . await {
132
+ Ok ( ctx) => Some (
133
+ ctx. with_context ( || format ! ( "Failed to create a temp file at {}" , cloned. display( ) ) ) ,
134
+ ) ,
135
+ _ => None ,
136
+ }
128
137
}
0 commit comments