Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rust 自定义属性因enum_分派宏而崩溃_Rust - Fatal编程技术网

Rust 自定义属性因enum_分派宏而崩溃

Rust 自定义属性因enum_分派宏而崩溃,rust,Rust,使用#[enum_dispatch]时,我遇到了一个不支持的参数类型错误。我下面的代码非常接近,所以我不确定问题可能是什么,因为这个错误消息非常不透明。有没有想过原因可能是什么,或者如何获得更详细的错误报告?我可以很好地运行这个示例,所以我认为这不是编译器的问题 enum_dispatch = "0.3.5" undo = {version = "0.46.0", features = ["colored"]} 如果您想运行,我用这段

使用
#[enum_dispatch]
时,我遇到了一个
不支持的参数类型
错误。我下面的代码非常接近,所以我不确定问题可能是什么,因为这个错误消息非常不透明。有没有想过原因可能是什么,或者如何获得更详细的错误报告?我可以很好地运行这个示例,所以我认为这不是编译器的问题

enum_dispatch = "0.3.5"
undo = {version = "0.46.0", features = ["colored"]}
如果您想运行,我用这段代码创建了一个。我打开了一个,回购所有人给了我一个响应。看来是
AppAction::merge
中的
\uu
导致了这种情况。相反,请尝试:

#[枚举调度(AppActionTest)]
酒馆特质惊骇{
fn应用(&mut self,target:&mut AppState)->结果;
fn撤消(&mut self,目标:&mut AppState)->结果;
fn重做(&mut self,目标:&mut AppState)->结果{
自我应用(目标)
}
fn合并(&mut self,_unused:&mut AppActionTest)->合并{
合并::否
}
}
编辑:此问题应在版本
enum\u dispatch 0.3.6
及更高版本中修复

use undo::{Action, History, Merged};
use enum_dispatch::enum_dispatch;

pub struct AppState{
    names: Vec<String>
}

#[enum_dispatch(AppActionTest)]
pub trait AppAction{
    fn apply(&mut self, target: &mut AppState) -> Result<(), String>;

    fn undo(&mut self, target: &mut AppState) -> Result<(), String>;

    fn redo(&mut self, target: &mut AppState) -> Result<(), String> {
        self.apply(target)
    }

    fn merge(&mut self, _: &mut AppActionTest) -> Merged {
        Merged::No
    }
}

pub struct AddMask;
impl Action for AddMask{
    type Target = AppState;
    type Output = ();
    type Error = String;
    fn apply(&mut self, target: &mut AppState) -> Result<(), String>{
        dbg!("APPLYING ADD MASK");
        Ok(())
    }
    fn undo(&mut self, target: &mut AppState) -> Result<(), String>{
        Ok(())
    }
    fn redo(&mut self, target: &mut AppState) -> Result<(), String> {
        self.apply(target)
    }
}

#[enum_dispatch]
pub enum AppActionTest {
    AM(AddMask)
}

fn main(){
    dbg!("running");
}
error: custom attribute panicked
  --> src\main.rs:41:1
   |
41 | #[enum_dispatch]
   | ^^^^^^^^^^^^^^^^
   |
   = help: message: Unsupported argument type

error[E0412]: cannot find type `AppActionTest` in this scope
  --> src\main.rs:19:33
   |
19 |     fn merge(&mut self, _: &mut AppActionTest) -> Merged {
   |                                 ^^^^^^^^^^^^^ not found in this scope