E4018#
无法为给定类型解析特征。
错误示例:#
struct S { v : Int }
let s : S = { v: 3 }
let t = Show::to_string(s)
在上述例子中,试图在类型 S
上调用 Show
特征的方法 to_string
,但由于 S
没有实现该特征,会在第 4 行报错:
Type S does not implement trait Show: method output is missing
建议#
给类型 S
实现 Show
特征:
struct S { v : Int }
let s : S = { v: 3 }
let t = Show::to_string(s)
impl Show for S with output(self, logger) {
logger.write_object(self.v)
}