1
- use crate :: { bail , Body , Mime } ;
1
+ use crate :: { Body , Mime } ;
2
2
3
3
use std:: fmt:: { self , Debug } ;
4
+ use std:: path:: Path ;
4
5
5
6
/// A single multipart entry.
6
7
///
@@ -21,24 +22,16 @@ impl Entry {
21
22
22
23
/// Create an empty `Entry`.
23
24
pub fn empty ( name : impl AsRef < str > ) -> Self {
24
- Self {
25
- name : name. as_ref ( ) . to_owned ( ) ,
26
- body : Body :: empty ( ) ,
27
- }
25
+ Self :: new ( name, Body :: empty ( ) )
28
26
}
29
27
30
28
/// Create an `Entry` from a file.
31
- ///
32
29
#[ cfg( all( feature = "async_std" , not( target_os = "unknown" ) ) ) ]
33
- pub async fn from_file < P > ( path : P ) -> crate :: Result < Self >
30
+ pub async fn from_file < S , P > ( name : S , path : P ) -> crate :: Result < Self >
34
31
where
35
- P : AsRef < std:: path:: Path > ,
32
+ S : AsRef < str > ,
33
+ P : AsRef < Path > ,
36
34
{
37
- let path = path. as_ref ( ) ;
38
- let name = match path. to_str ( ) {
39
- Some ( p) => p. to_owned ( ) ,
40
- None => bail ! ( "Could not convert file name to unicode" ) ,
41
- } ;
42
35
let body = Body :: from_file ( path) . await ?;
43
36
Ok ( Self :: new ( name, body) )
44
37
}
0 commit comments