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
///
@@ -12,33 +13,32 @@ pub struct Entry {
12
13
13
14
impl Entry {
14
15
/// Create a new `Entry`.
15
- pub fn new ( name : impl AsRef < str > , body : impl Into < Body > ) -> Self {
16
+ pub fn new < S , B > ( name : S , body : B ) -> Self
17
+ where
18
+ S : AsRef < str > ,
19
+ B : Into < Body > ,
20
+ {
16
21
Self {
17
22
name : name. as_ref ( ) . to_owned ( ) ,
18
23
body : body. into ( ) ,
19
24
}
20
25
}
21
26
22
27
/// Create an empty `Entry`.
23
- pub fn empty ( name : impl AsRef < str > ) -> Self {
24
- Self {
25
- name : name . as_ref ( ) . to_owned ( ) ,
26
- body : Body :: empty ( ) ,
27
- }
28
+ pub fn empty < S > ( name : S ) -> Self
29
+ where
30
+ S : AsRef < str > ,
31
+ {
32
+ Self :: new ( name , Body :: empty ( ) )
28
33
}
29
34
30
35
/// Create an `Entry` from a file.
31
- ///
32
36
#[ cfg( all( feature = "async_std" , not( target_os = "unknown" ) ) ) ]
33
- pub async fn from_file < P > ( path : P ) -> crate :: Result < Self >
37
+ pub async fn from_file < S , P > ( name : S , path : P ) -> crate :: Result < Self >
34
38
where
35
- P : AsRef < std:: path:: Path > ,
39
+ S : AsRef < str > ,
40
+ P : AsRef < Path > ,
36
41
{
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
42
let body = Body :: from_file ( path) . await ?;
43
43
Ok ( Self :: new ( name, body) )
44
44
}
0 commit comments