@@ -12,7 +12,6 @@ use log::debug;
1212use num_derive:: FromPrimitive ;
1313use rand:: RngCore ;
1414use std:: collections:: HashMap ;
15- use std:: error:: Error ;
1615use std:: time:: Duration ;
1716use thiserror:: Error ;
1817
@@ -22,7 +21,7 @@ use super::utils::{cross_sleep, to_sjis};
2221
2322/// An action to take on the player
2423#[ derive( Copy , Clone ) ]
25- enum Action {
24+ pub enum Action {
2625 Play = 0x75 ,
2726 Pause = 0x7d ,
2827 FastForward = 0x39 ,
@@ -251,6 +250,9 @@ pub enum EncryptionError {
251250
252251 #[ error( "supplied {0} length of {1} is invalid" ) ]
253252 InvalidLength ( & ' static str , usize ) ,
253+
254+ #[ error( "{0}" ) ]
255+ InvalidState ( & ' static str )
254256}
255257
256258/// An error for any action in the interface
@@ -494,14 +496,14 @@ impl NetMDInterface {
494496 data = self . device . read_reply ( None ) . await ?;
495497
496498 let status = NetmdStatus :: try_from ( data[ 0 ] ) ?;
497- debug ! ( "Device status: {:?}" , status ) ;
499+ debug ! ( "Device status: {status :?}" ) ;
498500
499501 match status {
500502 NetmdStatus :: NotImplemented => {
501- return Err ( InterfaceError :: NotImplemented ( format ! ( "{:02X?}" , data ) ) )
503+ return Err ( InterfaceError :: NotImplemented ( format ! ( "{data :02X?}" ) ) )
502504 }
503505 NetmdStatus :: Rejected => {
504- return Err ( InterfaceError :: Rejected ( format ! ( "{:02X?}" , data ) ) )
506+ return Err ( InterfaceError :: Rejected ( format ! ( "{data :02X?}" ) ) )
505507 }
506508 NetmdStatus :: Interim if !accept_interim => {
507509 let sleep_time = Self :: INTERIM_RESPONSE_RETRY_INTERVAL
@@ -518,15 +520,15 @@ impl NetMDInterface {
518520 }
519521 return Ok ( data) ;
520522 }
521- _ => return Err ( InterfaceError :: Unknown ( format ! ( "{:02X?}" , data ) ) ) ,
523+ _ => return Err ( InterfaceError :: Unknown ( format ! ( "{data :02X?}" ) ) ) ,
522524 }
523525 }
524526
525527 // This should NEVER happen unless the code is changed wrongly
526528 unreachable ! ( "The max number of retries is set to 0!" )
527529 }
528530
529- async fn playback_control ( & mut self , action : Action ) -> Result < ( ) , InterfaceError > {
531+ pub async fn playback_control ( & mut self , action : Action ) -> Result < ( ) , InterfaceError > {
530532 let query = format_query (
531533 "18c3 ff %b 000000" . to_string ( ) ,
532534 vec ! [ QueryValue :: Number ( action as i64 ) ] ,
@@ -974,9 +976,6 @@ impl NetMDInterface {
974976
975977 let raw_full_title = self . raw_disc_title ( true ) . await ?;
976978
977- dbg ! ( & raw_title) ;
978- dbg ! ( & raw_full_title) ;
979-
980979 let mut full_width_group_list = raw_full_title. split ( "//" ) ;
981980
982981 for ( i, group) in group_list. enumerate ( ) {
@@ -1029,8 +1028,7 @@ impl NetMDInterface {
10291028 for track in track_min - 1 ..track_max {
10301029 if track_dict. contains_key ( & track) {
10311030 return Err ( InterfaceError :: GroupError ( format ! (
1032- "track {} is in 2 groups" ,
1033- track
1031+ "track {track} is in 2 groups" ,
10341032 ) ) ) ;
10351033 }
10361034 track_dict. insert ( track, ( String :: from ( group_name) , i as u16 ) ) ;
@@ -1119,10 +1117,10 @@ impl NetMDInterface {
11191117 Ok ( title)
11201118 }
11211119
1122- // Sets the title of the disc
1123- //
1124- // Caution: This does not respect groups. Use the functions available in
1125- // NetMDContext to properly rename a disc.
1120+ /// Sets the title of the disc
1121+ ///
1122+ /// ## Caution: This does not respect groups.
1123+ /// Use the functions available in NetMDContext to properly rename a disc.
11261124 pub async fn set_disc_title ( & mut self , title : & str , wchar : bool ) -> Result < ( ) , InterfaceError > {
11271125 let current_title = self . raw_disc_title ( wchar) . await ?;
11281126 if current_title == title {
@@ -1948,7 +1946,7 @@ pub(super) struct MDSession<'a> {
19481946}
19491947
19501948impl < ' a > MDSession < ' a > {
1951- pub async fn init ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
1949+ pub async fn init ( & mut self ) -> Result < ( ) , InterfaceError > {
19521950 self . md . enter_secure_session ( ) . await ?;
19531951 self . md . leaf_id ( ) . await ?;
19541952
@@ -1971,7 +1969,7 @@ impl<'a> MDSession<'a> {
19711969 Ok ( ( ) )
19721970 }
19731971
1974- pub async fn close ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
1972+ pub async fn close ( & mut self ) -> Result < ( ) , InterfaceError > {
19751973 if self . hex_session_key . is_none ( ) {
19761974 self . md . session_key_forget ( ) . await ?;
19771975 }
@@ -1985,10 +1983,10 @@ impl<'a> MDSession<'a> {
19851983 mut track : MDTrack ,
19861984 progress_callback : F ,
19871985 disc_format : Option < DiscFormat > ,
1988- ) -> Result < ( u16 , Vec < u8 > , Vec < u8 > ) , Box < dyn Error > >
1986+ ) -> Result < ( u16 , Vec < u8 > , Vec < u8 > ) , InterfaceError >
19891987 {
19901988 if self . hex_session_key . is_none ( ) {
1991- return Err ( "Cannot download a track using a non-init()'ed session!" . into ( ) ) ;
1989+ return Err ( EncryptionError :: InvalidState ( "Cannot download a track using a non-init()'ed session!" ) . into ( ) ) ;
19921990 }
19931991 self . md
19941992 . setup_download (
0 commit comments