E4096#
字符串插值语法不能用于创建 Bytes 类型的值,只能用于创建 String 类型的值。
错误示例#
///|
test {
let x : Int = 42
let _ : Bytes = "(\{x})"
}
建议#
如果需要动态地创建类型为 Bytes 的值,可以使用带有显式 UTF-8 写入的 Buffer:
///|
test {
let x : Int = 42
let buf = Buffer()
let bytes : Bytes = buf
..write_string_utf8("(")
..write_utf8(x)
..write_string_utf8(")")
.to_bytes()
ignore(bytes)
}