pub fn core_mv(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "mv 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::rename(src, dst);
                match res {
                    Ok(_) => {}
                    Err(e) => {
                        let err_str =
                            format!("unable to move 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.
/// Moves the file corresponding to the first path to the second
/// path.  (Not quite the same semantics as mv(1), because it uses
/// rename(2) underneath, so that should be fixed.)
Takes two values that can be stringified as its arguments.
Moves the file corresponding to the first path to the second
path.  (Not quite the same semantics as mv(1), because it uses
rename(2) underneath, so that should be fixed.)
Takes two values that can be stringified as its arguments . Moves the file corresponding to the first path to the second path . ( Not quite the same semantics as mv ( 1 ) because it uses rename ( 2 ) underneath so that should be fixed . )
pub fn core_mv(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "mv 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::rename(src, dst);
                match res {
                    Ok(_) => {}
                    Err(e) => {
                        let err_str =
                            format!("unable to move 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_mv ( & 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 :: rename ( 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