我有一些代码可以正常类型,但当我添加泛型它会引发错误.
它给我以下错误,我的代码如下:
该特征
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)