@@ -2,20 +2,20 @@ use core::clone::Clone;
2
2
use core:: ops:: Deref ;
3
3
use diesel;
4
4
use diesel:: prelude:: * ;
5
- use diesel:: BelongingToDsl ;
6
5
use diesel:: types:: * ;
6
+ use diesel:: BelongingToDsl ;
7
7
use std:: path:: Path ;
8
8
9
9
#[ cfg( test) ]
10
10
use db;
11
11
use db:: ConnectionSource ;
12
- use db:: { playlists, playlist_songs, users} ;
12
+ use db:: { playlist_songs, playlists, users} ;
13
+ use errors:: * ;
13
14
use index:: { self , Song } ;
14
15
use vfs:: VFSSource ;
15
- use errors:: * ;
16
16
17
17
#[ derive( Insertable ) ]
18
- #[ table_name= "playlists" ]
18
+ #[ table_name = "playlists" ]
19
19
struct NewPlaylist {
20
20
name : String ,
21
21
owner : i32 ,
@@ -27,29 +27,30 @@ pub struct User {
27
27
}
28
28
29
29
#[ derive( Identifiable , Queryable , Associations ) ]
30
- #[ belongs_to( User , foreign_key= "owner" ) ]
30
+ #[ belongs_to( User , foreign_key = "owner" ) ]
31
31
pub struct Playlist {
32
32
id : i32 ,
33
33
owner : i32 ,
34
34
}
35
35
36
36
#[ derive( Identifiable , Queryable , Associations ) ]
37
- #[ belongs_to( Playlist , foreign_key= "playlist" ) ]
37
+ #[ belongs_to( Playlist , foreign_key = "playlist" ) ]
38
38
pub struct PlaylistSong {
39
39
id : i32 ,
40
40
playlist : i32 ,
41
41
}
42
42
43
43
#[ derive( Insertable ) ]
44
- #[ table_name= "playlist_songs" ]
44
+ #[ table_name = "playlist_songs" ]
45
45
pub struct NewPlaylistSong {
46
46
playlist : i32 ,
47
47
path : String ,
48
48
ordering : i32 ,
49
49
}
50
50
51
51
pub fn list_playlists < T > ( owner : & str , db : & T ) -> Result < Vec < String > >
52
- where T : ConnectionSource + VFSSource
52
+ where
53
+ T : ConnectionSource + VFSSource ,
53
54
{
54
55
let connection = db. get_connection ( ) ;
55
56
@@ -71,12 +72,9 @@ pub fn list_playlists<T>(owner: &str, db: &T) -> Result<Vec<String>>
71
72
}
72
73
}
73
74
74
- pub fn save_playlist < T > ( playlist_name : & str ,
75
- owner : & str ,
76
- content : & [ String ] ,
77
- db : & T )
78
- -> Result < ( ) >
79
- where T : ConnectionSource + VFSSource
75
+ pub fn save_playlist < T > ( playlist_name : & str , owner : & str , content : & [ String ] , db : & T ) -> Result < ( ) >
76
+ where
77
+ T : ConnectionSource + VFSSource ,
80
78
{
81
79
let user: User ;
82
80
let new_playlist: NewPlaylist ;
@@ -119,14 +117,16 @@ pub fn save_playlist<T>(playlist_name: &str,
119
117
120
118
for ( i, path) in content. iter ( ) . enumerate ( ) {
121
119
let virtual_path = Path :: new ( & path) ;
122
- if let Some ( real_path) = vfs. virtual_to_real ( virtual_path)
123
- . ok ( )
124
- . and_then ( |p| p. to_str ( ) . map ( |s| s. to_owned ( ) ) ) {
120
+ if let Some ( real_path) = vfs
121
+ . virtual_to_real ( virtual_path)
122
+ . ok ( )
123
+ . and_then ( |p| p. to_str ( ) . map ( |s| s. to_owned ( ) ) )
124
+ {
125
125
new_songs. push ( NewPlaylistSong {
126
- playlist : playlist. id ,
127
- path : real_path,
128
- ordering : i as i32 ,
129
- } ) ;
126
+ playlist : playlist. id ,
127
+ path : real_path,
128
+ ordering : i as i32 ,
129
+ } ) ;
130
130
}
131
131
}
132
132
@@ -151,7 +151,8 @@ pub fn save_playlist<T>(playlist_name: &str,
151
151
}
152
152
153
153
pub fn read_playlist < T > ( playlist_name : & str , owner : & str , db : & T ) -> Result < Vec < Song > >
154
- where T : ConnectionSource + VFSSource
154
+ where
155
+ T : ConnectionSource + VFSSource ,
155
156
{
156
157
let vfs = db. get_vfs ( ) ?;
157
158
let songs: Vec < Song > ;
@@ -201,7 +202,8 @@ pub fn read_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<Vec<
201
202
}
202
203
203
204
pub fn delete_playlist < T > ( playlist_name : & str , owner : & str , db : & T ) -> Result < ( ) >
204
- where T : ConnectionSource + VFSSource
205
+ where
206
+ T : ConnectionSource + VFSSource ,
205
207
{
206
208
let connection = db. get_connection ( ) ;
207
209
0 commit comments