File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ pub enum ISOError {
1515 ParseInt ( ParseIntError ) ,
1616 ReadSize ( usize , usize ) ,
1717 Nom ( nom:: error:: ErrorKind ) ,
18+ IntoInner ( & ' static str ) ,
1819}
1920
2021impl Display for ISOError {
@@ -30,6 +31,7 @@ impl Display for ISOError {
3031 size, size_read
3132 ) ,
3233 ISOError :: Nom ( ref err) => write ! ( f, "Parse error: {:?}" , err) ,
34+ ISOError :: IntoInner ( msg) => write ! ( f, "Into inner error: {}" , msg) ,
3335 }
3436 }
3537}
Original file line number Diff line number Diff line change @@ -61,4 +61,14 @@ impl<T: ISO9660Reader> FileRef<T> {
6161 pub fn read_at ( & self , buf : & mut [ u8 ] , lba : u64 ) -> Result < usize > {
6262 ( * self . 0 ) . borrow_mut ( ) . read_at ( buf, lba)
6363 }
64+
65+ /// Try returning inner value (will work if Rc has exactly one strong ref)
66+ /// Returns Self on error
67+ pub fn try_into_inner ( self ) -> std:: result:: Result < T , Self > {
68+ match Rc :: < RefCell < T > > :: try_unwrap ( self . 0 ) {
69+ Ok ( refcell) => Ok ( refcell. into_inner ( ) ) ,
70+ Err ( rcrefcell) => Err ( FileRef ( rcrefcell) )
71+ }
72+ }
73+
6474}
Original file line number Diff line number Diff line change @@ -125,6 +125,16 @@ impl<T: ISO9660Reader> ISO9660<T> {
125125 2048 // XXX
126126 }
127127
128+ /// Returns inner reader, consuming self.
129+ /// This will fail if references to T are still used (e.g. ISODirectory<T> or ISOFile<T>).
130+ pub fn try_into_inner ( self ) -> Result < T > {
131+ // Drop root first since it owns a _file ref
132+ drop ( self . root ) ;
133+ self . _file . try_into_inner ( ) . map_err ( |_|
134+ ISOError :: IntoInner ( "Inner reader still referenced" )
135+ )
136+ }
137+
128138 primary_prop_str ! ( volume_set_identifier) ;
129139 primary_prop_str ! ( publisher_identifier) ;
130140 primary_prop_str ! ( data_preparer_identifier) ;
You can’t perform that action at this time.
0 commit comments