无法在异步函数中更改 pathBuff/path 变量

问题描述

我不确定是否应该在此处或在代码审查中发布此内容。 代码审查似乎只有正常运行的代码。

所以我有很多我不明白的问题。 (我是菜鸟)可以在这里找到完整的代码:https://github.com/NicTanghe/winder/blob/main/src/main.rs 主要问题在这里:

let temp = location_loc1.parent().unwrap();
location_loc1.push(&temp);

我尝试了各种方法来解决将借用作为可变或参考借用的问题, 我似乎无法让它工作。

我尝试的每件事都出现了一组不同的错误。 此外,如果这是重复的,我很抱歉,但是寻找错误的单独解决方案只是给了我一个不同的错误。围成一圈。

功能齐全

async fn print_events(mut selector_loc1:i8,location_loc1: PathBuf) {
    let mut reader = EventStream::new();

    loop {
        //let delay = Delay::new(Duration::from_millis(1_000)).fuse();
        let mut event = reader.next().fuse();

        select! {
            // _ = delay => {
            //      print!("{esc}[2J{esc}[1;1H{}",esc = 27 as char,); 
                 
            // },maybe_event = event => {
                match maybe_event {
                    Some(Ok(event)) => {
                        //println!("Event::{:?}\r",event);
                        
                        // if event == Event::Mouse(MouseEvent::Up("Left").into()) {
                        //     println!("Cursor position: {:?}\r",position());
                        // }   
                        print!("{esc}[2J{esc}[1;1H{}",); 
                        if event == Event::Key(KeyCode::Char('k').into()) {
                            if selector_loc1 > 0 {
                                selector_loc1 -= 1;
                            };
                            //println!("go down");
                            //println!("{}",selected)

                        }   else if event == Event::Key(KeyCode::Char('j').into()) {
                            selector_loc1 += 1;
                            //println!("go up");
                            //println!("{}",selected)
                        }   else if event == Event::Key(KeyCode::Char('h').into()) {


                        //-----------------------------------------
                        //-------------BackLogic-------------------
                        //-----------------------------------------
                            let temp = location_loc1.parent().unwrap();
                            location_loc1.push(&temp);
                            
                        //------------------------------------------
                        //------------------------------------------

                        }   else if event == Event::Key(KeyCode::Char('l').into()) {
                            //go to next dir

                        }   if event == Event::Key(KeyCode::Esc.into()) {
                            break;
                        }

                        printtype(location_loc1,selector_loc1);

                    }
                    Some(Err(e)) => println!("Error: {:?}\r",e),None => break,}
            }
        };
    }
}

还有,好像用

use async_std::path::{Path,PathBuf};

使 rust 无法识别 unwrap() 函数 → 我将如何使用 using ?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)