相关疑难解决方法(0)

5
推荐指数
1
解决办法
559
查看次数

使用未声明的类型或模块核心:: fmt :: Display

我有一些代码可以正常类型,但当我添加泛型它会引发错误.

它给我以下错误,我的代码如下:

该特征core::fmt::Display未针对T[E0277] 类型实施

fn own<T>(x: T) -> T 
{ 
    x 
}

struct Node<T>
{
    value: T,
    next: Option<Box<Node<T>>>
}

impl<T> Node<T>
{
    fn print(&self)
    {
        let mut current = self;
        loop {
            println!("{}", current.value);
            match current.next {
                Some(ref next) => { current = &**next; },
                None => break,
            }
        } 
    }

    fn add(&mut self, node: Node<T>)
    {
        let item = Some(Box::new(node));
        let mut current = self;
        loop {
            match own(current).next {
                ref mut slot @ …
Run Code Online (Sandbox Code Playgroud)

rust

4
推荐指数
1
解决办法
1444
查看次数

标签 统计

rust ×2

asynchronous ×1

task ×1