2025-05-19
语言更新
x..f(..)
的语义即将发生改变,在 ./.. 调用链末尾的最后一个 .. 以后会自动丢弃它的值。因此,下面的代码:
impl[X : Show, Y : Show] Show for (X, Y) with output(self, logger) {
logger
..write_string("(")
..write_object(self.0)
..write_string(", ")
..write_object(self.1)
// 原本,这里必须写 `.`,否则整个 `.` 链的类型是 `&Logger`,不符合预期类型 `Unit`
.write_string(")")
}
以后可以简化成
impl[X : Show, Y : Show] Show for (X, Y) with output(self, logger) {
logger
..write_string("(")
..write_object(self.0)
..write_string(", ")
..write_object(self.1)
// 以后可以直接一路 `..` 到底了
..write_string(")")
}
但这也意味着直接使用 x..f()
的值的用法将会被废弃,需要显式保存x
。例如,下面的代码:
let arr = []..push(1)..push(2)
需要改写成:
let arr = []
arr..push(1)..push(2)
枚举构造器和结构体的字段支持单独的文档注释,在补全时会显示相应的文档。
///| Location enum
struct Location {
/// X coordinate
x : Int
/// y coordinate
y : Int
}
///| Variant enum
enum Variant {
/// Stirng constructor
String(String)
/// Number constructor
Number(Double)
}