pub fn core_close(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 1 {
            print_error(chunk, i, "close requires one argument");
            return 0;
        }

        let file_rr = self.stack.pop().unwrap();
        let mut file_rrb = file_rr.borrow_mut();

        match *file_rrb {
            Value::FileReader(_) => {
                // No action required.
                return 1;
            }
            Value::FileWriter(ref mut line_writer) => {
                let res = line_writer.flush();
                match res {
                    Ok(_) => {
                        return 1;
                    }
                    Err(e) => {
                        let err_str = format!(
                            "unable to flush data: {}",
                            e.to_string()
                        );
                        print_error(chunk, i, &err_str);
                        return 0;
                    }
                }
            }
            _ => {
                print_error(chunk, i, "close argument must be a file reader or writer");
                return 0;
            }
        }
    }
/// Takes a FileReader or FileWriter object as its single
/// argument.  Closes the object, if required.
Takes a FileReader or FileWriter object as its single
argument.  Closes the object, if required.
Takes a FileReader or FileWriter object as its single argument . Closes the object if required .
pub fn core_close(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 1 {
            print_error(chunk, i, "close requires one argument");
            return 0;
        }
        let file_rr = self.stack.pop().unwrap();
        let mut file_rrb = file_rr.borrow_mut();
        match *file_rrb {
            Value::FileReader(_) => {
                // No action required.
                return 1;
            }
            Value::FileWriter(ref mut line_writer) => {
                let res = line_writer.flush();
                match res {
                    Ok(_) => {
                        return 1;
                    }
                    Err(e) => {
                        let err_str = format!(
                            "unable to flush data: {}",
                            e.to_string()
                        );
                        print_error(chunk, i, &err_str);
                        return 0;
                    }
                }
            }
            _ => {
                print_error(chunk, i, "close argument must be a file reader or writer");
                return 0;
            }
        }
    }
pub fn core_close ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) < 1 { print_error ( chunk , i , " " ) ; return 0 ; } let file_rr = self . stack . pop ( ) . unwrap ( ) ; let mut file_rrb = file_rr . borrow_mut ( ) ; match * file_rrb { Value :: FileReader ( _ ) => { // No action required. return 1 ; } Value :: FileWriter ( ref mut line_writer ) => { let res = line_writer . flush ( ) ; match res { Ok ( _ ) => { return 1 ; } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } }
Takes a FileReader or FileWriter object as its single
argument.
Takes a FileReader or FileWriter object as its single argument .
&mut self
chunk
&Chunk
i
usize