mirror of
				https://github.com/Dummi26/musicdb.git
				synced 2025-10-30 03:25:26 +01:00 
			
		
		
		
	update lib
This commit is contained in:
		
							parent
							
								
									594909e745
								
							
						
					
					
						commit
						7d6d6d295b
					
				
							
								
								
									
										43
									
								
								musicdb-lib/src/server/simple.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								musicdb-lib/src/server/simple.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | |||||||
|  | use std::{ | ||||||
|  |     io::{BufRead, BufReader, Read, Write}, | ||||||
|  |     sync::{mpsc, Arc, Mutex}, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | use crate::data::database::Database; | ||||||
|  | 
 | ||||||
|  | use super::Command; | ||||||
|  | 
 | ||||||
|  | pub fn handle_main<T: Read + Write>( | ||||||
|  |     db: Arc<Mutex<Database>>, | ||||||
|  |     con: &mut BufReader<T>, | ||||||
|  |     command_sender: &mpsc::Sender<Command>, | ||||||
|  | ) -> Result<(), std::io::Error> { | ||||||
|  |     loop { | ||||||
|  |         let mut command = String::new(); | ||||||
|  |         con.read_line(&mut command)?; | ||||||
|  |         let command = command.trim(); | ||||||
|  |         let (command, args) = command.split_once(' ').unwrap_or((command, "")); | ||||||
|  |         match command { | ||||||
|  |             "goodbye" => return Ok(()), | ||||||
|  |             "list-artists" => { | ||||||
|  |                 for (id, artist) in db.lock().unwrap().artists().iter() { | ||||||
|  |                     writeln!(con.get_mut(), "#{id}:{}", artist.name)?; | ||||||
|  |                 } | ||||||
|  |                 writeln!(con.get_mut(), "---")?; | ||||||
|  |             } | ||||||
|  |             "list-albums" => { | ||||||
|  |                 for (id, album) in db.lock().unwrap().albums().iter() { | ||||||
|  |                     writeln!(con.get_mut(), "#{id}:{}", album.name)?; | ||||||
|  |                 } | ||||||
|  |                 writeln!(con.get_mut(), "---")?; | ||||||
|  |             } | ||||||
|  |             "list-songs" => { | ||||||
|  |                 for (id, song) in db.lock().unwrap().songs().iter() { | ||||||
|  |                     writeln!(con.get_mut(), "#{id}:{}", song.title)?; | ||||||
|  |                 } | ||||||
|  |                 writeln!(con.get_mut(), "---")?; | ||||||
|  |             } | ||||||
|  |             _ => writeln!(con.get_mut(), "err: no such command")?, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Mark
						Mark