【问题标题】:Mismatched types: `expected fn@(&&@type) -> uint` but found `extern fn(@map_a) -> uint` (expected argument mode ++ but found &&)不匹配的类型:`expected fn@(&&@type) -> uint` but found `extern fn(@map_a) -> uint`(预期的参数模式 ++ 但找到了 &&)
【发布时间】:2012-07-16 20:27:46
【问题描述】:
$ rustc --test mapAsMapKey.rs 
mapAsMapKey.rs:18:43: 18:52 error: mismatched types: expected `fn@(&&@map_a) -> uint` but found `extern fn(@map_a) -> uint` (expected argument mode ++ but found &&)
mapAsMapKey.rs:18     let b: map_b = hashmap::<@map_a, uint>(rmap_hash, rmap_eqer);
                                                             ^~~~~~~~~
mapAsMapKey.rs:18:54: 18:63 error: mismatched types: expected `fn@(&&@map_a, &&@map_a) -> bool` but found `extern fn(@map_a, @map_b) -> bool` (expected argument mode ++ but found &&)
mapAsMapKey.rs:18     let b: map_b = hashmap::<@map_a, uint>(rmap_hash, rmap_eqer);
                                                                        ^~~~~~~~~
error: aborting due to 2 previous errors

防锈功能:

fn rmap_hash (m: @map_a) -> uint { 0 }
fn rmap_eqer (m1: @map_a, m2: @map_b) -> bool { true }

线路触发:

let b: map_b = hashmap::<@map_a, uint>(rmap_hash, rmap_eqer);

【问题讨论】:

    标签: types rust


    【解决方案1】:

    如果你这样写 Rust 函数,它会工作吗?

    fn rmap_hash (&&m: @map_a) -> uint { 0 }
    
    fn rmap_eqer (&&m1: @map_a, &&m2: @map_b) -> bool { true }
    

    【讨论】:

    • 是的。正如你在 IRC 上所说。虽然我仍然不确定它们是什么。
    猜你喜欢
    • 1970-01-01
    • 2022-07-19
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 2021-10-10
    • 2022-08-17
    相关资源
    最近更新 更多