33use std:: env;
44use std:: path:: PathBuf ;
55use std:: process:: Stdio ;
6- use tokio:: process:: Command ;
76use thiserror:: Error ;
7+ use tokio:: process:: Command ;
88use tracing:: { debug, error, warn} ;
99
1010/// Errors that can occur when using LinkDBService
@@ -72,7 +72,11 @@ impl LinkDBService {
7272 after : bool ,
7373 trace : bool ,
7474 ) -> Result < String , LinkDBError > {
75- let mut args = vec ! [ query. to_string( ) , "--db" . to_string( ) , self . db_path. to_string_lossy( ) . to_string( ) ] ;
75+ let mut args = vec ! [
76+ query. to_string( ) ,
77+ "--db" . to_string( ) ,
78+ self . db_path. to_string_lossy( ) . to_string( ) ,
79+ ] ;
7680
7781 if before {
7882 args. push ( "--before" . to_string ( ) ) ;
@@ -169,7 +173,9 @@ impl LinkDBService {
169173 /// * `target` - Target link ID
170174 pub async fn create_link ( & self , source : u64 , target : u64 ) -> Result < Link , LinkDBError > {
171175 let query = format ! ( "() (({} {}))" , source, target) ;
172- let output = self . execute_query ( & query, false , true , false , false ) . await ?;
176+ let output = self
177+ . execute_query ( & query, false , true , false , false )
178+ . await ?;
173179
174180 let re = regex_lite:: Regex :: new ( r"\((\d+):\s+(\d+)\s+(\d+)\)" ) . unwrap ( ) ;
175181 if let Some ( caps) = re. captures ( & output) {
@@ -184,7 +190,9 @@ impl LinkDBService {
184190 }
185191 }
186192
187- Err ( LinkDBError :: ParseError ( "Failed to parse created link" . to_string ( ) ) )
193+ Err ( LinkDBError :: ParseError (
194+ "Failed to parse created link" . to_string ( ) ,
195+ ) )
188196 }
189197
190198 /// Read all links from database
@@ -197,7 +205,9 @@ impl LinkDBService {
197205 /// Read a specific link by ID
198206 pub async fn read_link ( & self , id : u64 ) -> Result < Option < Link > , LinkDBError > {
199207 let query = format ! ( "((({}:$s $t)) (({}:$s $t)))" , id, id) ;
200- let output = self . execute_query ( & query, false , false , true , false ) . await ?;
208+ let output = self
209+ . execute_query ( & query, false , false , true , false )
210+ . await ?;
201211 let links = self . parse_links ( & output) ;
202212 Ok ( links. into_iter ( ) . next ( ) )
203213 }
@@ -215,8 +225,12 @@ impl LinkDBService {
215225 new_source : u64 ,
216226 new_target : u64 ,
217227 ) -> Result < Link , LinkDBError > {
218- let query = format ! ( "((({}:$s $t)) (({}: {} {})))" , id, id, new_source, new_target) ;
219- self . execute_query ( & query, false , true , false , false ) . await ?;
228+ let query = format ! (
229+ "((({}:$s $t)) (({}: {} {})))" ,
230+ id, id, new_source, new_target
231+ ) ;
232+ self . execute_query ( & query, false , true , false , false )
233+ . await ?;
220234
221235 Ok ( Link {
222236 id,
@@ -228,7 +242,8 @@ impl LinkDBService {
228242 /// Delete a link
229243 pub async fn delete_link ( & self , id : u64 ) -> Result < bool , LinkDBError > {
230244 let query = format ! ( "((({}:$s $t)) ())" , id) ;
231- self . execute_query ( & query, false , true , false , false ) . await ?;
245+ self . execute_query ( & query, false , true , false , false )
246+ . await ?;
232247 Ok ( true )
233248 }
234249
@@ -246,7 +261,10 @@ impl LinkDBService {
246261 /// Get all menu items
247262 pub async fn get_all_menu_items ( & self ) -> Result < Vec < Link > , LinkDBError > {
248263 let all_links = self . read_all_links ( ) . await ?;
249- Ok ( all_links. into_iter ( ) . filter ( |link| link. target == 1000 ) . collect ( ) )
264+ Ok ( all_links
265+ . into_iter ( )
266+ . filter ( |link| link. target == 1000 )
267+ . collect ( ) )
250268 }
251269
252270 /// Delete menu item
@@ -276,8 +294,22 @@ mod tests {
276294 let links = service. parse_links ( output) ;
277295
278296 assert_eq ! ( links. len( ) , 2 ) ;
279- assert_eq ! ( links[ 0 ] , Link { id: 1 , source: 2 , target: 3 } ) ;
280- assert_eq ! ( links[ 1 ] , Link { id: 4 , source: 5 , target: 6 } ) ;
297+ assert_eq ! (
298+ links[ 0 ] ,
299+ Link {
300+ id: 1 ,
301+ source: 2 ,
302+ target: 3
303+ }
304+ ) ;
305+ assert_eq ! (
306+ links[ 1 ] ,
307+ Link {
308+ id: 4 ,
309+ source: 5 ,
310+ target: 6
311+ }
312+ ) ;
281313 }
282314
283315 #[ test]
0 commit comments