pub fn core_cp(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "cp requires two arguments");
            return 0;
        }

        let dst_rr = self.stack.pop().unwrap();
        let dst_rrb = dst_rr.borrow();
        let dst_pre = dst_rrb.to_string();
        let dst_opt = to_string_2(&dst_pre);

        let src_rr = self.stack.pop().unwrap();
        let src_rrb = src_rr.borrow();
        let src_pre = src_rrb.to_string();
        let src_opt = to_string_2(&src_pre);

        match (src_opt, dst_opt) {
            (Some(src), Some(dst)) => {
                let res = std::fs::copy(src, dst);
                match res {
                    Ok(_) => {}
                    Err(e) => {
                        let err_str =
                            format!("unable to copy file: {}", e.to_string());
                        print_error(chunk, i, &err_str);
                        return 0;
                    }
                }
            }
            _ => {
                print_error(chunk, i, "source and destination must be strings");
                return 0;
            }
        }
        return 1;
    }
/// Takes two values that can be stringified as its arguments.
/// Copies the file corresponding to the first path to the second
/// path.
Takes two values that can be stringified as its arguments.
Copies the file corresponding to the first path to the second
path.
Takes two values that can be stringified as its arguments . Copies the file corresponding to the first path to the second path .
pub fn core_cp(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "cp requires two arguments");
            return 0;
        }
        let dst_rr = self.stack.pop().unwrap();
        let dst_rrb = dst_rr.borrow();
        let dst_pre = dst_rrb.to_string();
        let dst_opt = to_string_2(&dst_pre);
        let src_rr = self.stack.pop().unwrap();
        let src_rrb = src_rr.borrow();
        let src_pre = src_rrb.to_string();
        let src_opt = to_string_2(&src_pre);
        match (src_opt, dst_opt) {
            (Some(src), Some(dst)) => {
                let res = std::fs::copy(src, dst);
                match res {
                    Ok(_) => {}
                    Err(e) => {
                        let err_str =
                            format!("unable to copy file: {}", e.to_string());
                        print_error(chunk, i, &err_str);
                        return 0;
                    }
                }
            }
            _ => {
                print_error(chunk, i, "source and destination must be strings");
                return 0;
            }
        }
        return 1;
    }
pub fn core_cp ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) < 2 { print_error ( chunk , i , " " ) ; return 0 ; } let dst_rr = self . stack . pop ( ) . unwrap ( ) ; let dst_rrb = dst_rr . borrow ( ) ; let dst_pre = dst_rrb . to_string ( ) ; let dst_opt = to_string_2 ( & dst_pre ) ; let src_rr = self . stack . pop ( ) . unwrap ( ) ; let src_rrb = src_rr . borrow ( ) ; let src_pre = src_rrb . to_string ( ) ; let src_opt = to_string_2 ( & src_pre ) ; match ( src_opt , dst_opt ) { ( Some ( src ) , Some ( dst ) ) => { let res = std :: fs :: copy ( src , dst ) ; match res { Ok ( _ ) => { } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } return 1 ; }
Takes two values that can be stringified as its arguments.
Takes two values that can be stringified as its arguments .
&mut self
chunk
&Chunk
i
usize