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 @@ -13,6 +13,7 @@ pub enum ISOError {
1313 ParseInt ( ParseIntError ) ,
1414 ReadSize ( usize , usize ) ,
1515 Nom ( nom:: error:: ErrorKind ) ,
16+ IntoInner ( & ' static str ) ,
1617}
1718
1819impl Display for ISOError {
@@ -28,6 +29,7 @@ impl Display for ISOError {
2829 size, size_read
2930 ) ,
3031 ISOError :: Nom ( ref err) => write ! ( f, "Parse error: {:?}" , err) ,
32+ ISOError :: IntoInner ( msg) => write ! ( f, "Into inner error: {}" , msg) ,
3133 }
3234 }
3335}
Original file line number Diff line number Diff line change @@ -62,4 +62,14 @@ impl<T: ISO9660Reader> FileRef<T> {
6262 pub fn read_at ( & self , buf : & mut [ u8 ] , lba : u64 ) -> Result < usize > {
6363 ( * self . 0 ) . borrow_mut ( ) . read_at ( buf, lba)
6464 }
65+
66+ /// Try returning inner value (will work if Rc has exactly one strong ref)
67+ /// Returns Self on error
68+ pub fn try_into_inner ( self ) -> std:: result:: Result < T , Self > {
69+ match Rc :: < RefCell < T > > :: try_unwrap ( self . 0 ) {
70+ Ok ( refcell) => Ok ( refcell. into_inner ( ) ) ,
71+ Err ( rcrefcell) => Err ( FileRef ( rcrefcell) )
72+ }
73+ }
74+
6575}
Original file line number Diff line number Diff line change @@ -126,6 +126,16 @@ impl<T: ISO9660Reader> ISO9660<T> {
126126 2048 // XXX
127127 }
128128
129+ /// Returns inner reader, consuming self.
130+ /// This will fail if references to T are still used (e.g. ISODirectory<T> or ISOFile<T>).
131+ pub fn try_into_inner ( self ) -> Result < T > {
132+ // Drop root first since it owns a _file ref
133+ drop ( self . root ) ;
134+ self . _file . try_into_inner ( ) . map_err ( |_|
135+ ISOError :: IntoInner ( "Inner reader still referenced" )
136+ )
137+ }
138+
129139 primary_prop_str ! ( volume_set_identifier) ;
130140 primary_prop_str ! ( publisher_identifier) ;
131141 primary_prop_str ! ( data_preparer_identifier) ;
You can’t perform that action at this time.
0 commit comments