fn init_ram(&mut self) -> IoResult<()> {
        let (rambanks, banksize) = match self.parse_ram_banks() {
            Some(v) => v,
            None    => panic!("Can't determine RAM size"),
        };

        let ramsize = rambanks * banksize;

        if ramsize == 0 {
            // No RAM on this cartridge, we're done
            return Ok(());
        }

        // We have some RAM, open the save file or create it if it
        // doesn't exist yet
        let mut savepath = self.path.clone();
        savepath.set_extension("sav");

        let mut save_file = try!(OpenOptions::new()
                                 .read(true)
                                 .write(true)
                                 .create(true)
                                 .open(savepath.clone()));

        let save_size = try!(save_file.metadata()).len();

        if save_size == 0 {
            // The file is empty (probably new). initialize
            // the RAM with 0s.
            self.ram = vec![0; ramsize];
            // Then fill the file with the right amount of 0s
            // to reserve enough space for saving later.
            try!(save_file.write_all(&self.ram));
        } else if save_size == (ramsize as u64) {
            // The file contains a RAM image
            try!((&mut save_file).take(ramsize as u64).read_to_end(&mut self.ram));
        } else {
            panic!("Unexpected save file size for {}: expected {} got {}",
                   savepath.display(), ramsize, save_size);
        }

        // Store the file handle to save progress later
        self.save_file = Some(save_file);

        Ok(())
    }
/// Init cartridge RAM and tie it with a `File` for saving if
/// necessary.
Init cartridge RAM and tie it with a `File` for saving if
necessary.
Init cartridge RAM and tie it with a ` File ` for saving if necessary .
fn init_ram(&mut self) -> IoResult<()> {
        let (rambanks, banksize) = match self.parse_ram_banks() {
            Some(v) => v,
            None    => panic!("Can't determine RAM size"),
        };
        let ramsize = rambanks * banksize;
        if ramsize == 0 {
            // No RAM on this cartridge, we're done
            return Ok(());
        }
        // We have some RAM, open the save file or create it if it
        // doesn't exist yet
        let mut savepath = self.path.clone();
        savepath.set_extension("sav");
        let mut save_file = try!(OpenOptions::new()
                                 .read(true)
                                 .write(true)
                                 .create(true)
                                 .open(savepath.clone()));
        let save_size = try!(save_file.metadata()).len();
        if save_size == 0 {
            // The file is empty (probably new). initialize
            // the RAM with 0s.
            self.ram = vec![0; ramsize];
            // Then fill the file with the right amount of 0s
            // to reserve enough space for saving later.
            try!(save_file.write_all(&self.ram));
        } else if save_size == (ramsize as u64) {
            // The file contains a RAM image
            try!((&mut save_file).take(ramsize as u64).read_to_end(&mut self.ram));
        } else {
            panic!("Unexpected save file size for {}: expected {} got {}",
                   savepath.display(), ramsize, save_size);
        }
        // Store the file handle to save progress later
        self.save_file = Some(save_file);
        Ok(())
    }
fn init_ram ( & mut self ) -> IoResult < ( ) > { let ( rambanks , banksize ) = match self . parse_ram_banks ( ) { Some ( v ) => v , None => panic ! ( " " ) , } ; let ramsize = rambanks * banksize ; if ramsize == 0 { // No RAM on this cartridge, we're done return Ok ( ( ) ) ; } // We have some RAM, open the save file or create it if it // doesn't exist yet let mut savepath = self . path . clone ( ) ; savepath . set_extension ( " " ) ; let mut save_file = try ! ( OpenOptions new ( ) read ( true ) write ( true ) create ( true ) open ( savepath clone ( ) ) ) ; let save_size = try ! ( save_file metadata ( ) ) . len ( ) ; if save_size == 0 { // The file is empty (probably new). initialize // the RAM with 0s. self . ram = vec ! [ 0 ramsize ] ; // Then fill the file with the right amount of 0s // to reserve enough space for saving later. try ! ( save_file write_all ( self ram ) ) ; } else if save_size == ( ramsize as u64 ) { // The file contains a RAM image try ! ( ( mut save_file ) take ( ramsize as u64 ) read_to_end ( mut self ram ) ) ; } else { panic ! ( " " savepath display ( ) ramsize save_size ) ; } // Store the file handle to save progress later self . save_file = Some ( save_file ) ; Ok ( ( ) ) }
Init cartridge RAM and tie it with a `File` for saving if
necessary.
Init cartridge RAM and tie it with a ` File ` for saving if necessary .
&mut self
&mut self