如何处理“范围内有多个适用项目”错误?

ANi*_*120 4 rust

我正在使用fltk-rs板条箱并遇到“范围内多个适用项目”错误。

fltk = "0.10.14"
Run Code Online (Sandbox Code Playgroud)
use fltk::{table::*};

pub struct AssetViewer {
    pub table: Table, 
}

impl AssetViewer {
    pub fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
        let mut av = AssetViewer {
            table: Table::new(x,y,width-50,height,""),

        };
        av.table.set_rows(5);
        av.table.set_cols(5);
        av
    }
    pub fn load_file_images(&mut self, asset_paths: Vec<String>){
        self.table.clear(); //<- throws multiple applicable items in scope
    }
}
Run Code Online (Sandbox Code Playgroud)

给出错误:

use fltk::{table::*};

pub struct AssetViewer {
    pub table: Table, 
}

impl AssetViewer {
    pub fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
        let mut av = AssetViewer {
            table: Table::new(x,y,width-50,height,""),

        };
        av.table.set_rows(5);
        av.table.set_cols(5);
        av
    }
    pub fn load_file_images(&mut self, asset_paths: Vec<String>){
        self.table.clear(); //<- throws multiple applicable items in scope
    }
}
Run Code Online (Sandbox Code Playgroud)

我想指出的是,我指的是TableExt特征,而不是GroupExt特征。我该怎么做?

Iva*_*n C 5

TLDR:使用完全限定的函数名称:

fltk::GroupExt::clear(&mut self.table)
Run Code Online (Sandbox Code Playgroud)

考虑这个简化的例子:

struct Bar;

trait Foo1 {
    fn foo(&self) {}
}
trait Foo2 {
    fn foo(&self) {}
}
impl Foo1 for Bar {}
impl Foo2 for Bar {}

fn main() {
    let a = Bar;
    a.foo()
}
Run Code Online (Sandbox Code Playgroud)

它将无法编译并显示以下错误消息:

error[E0034]: multiple applicable items in scope
  --> src/main.rs:16:7
   |
16 |     a.foo()
   |       ^^^ multiple `foo` found
   |
Run Code Online (Sandbox Code Playgroud)

编译器还会建议一个解决方案:

help: disambiguate the associated function for candidate #1
   |
16 |     Foo1::foo(&a)
   |
Run Code Online (Sandbox Code Playgroud)