其他
MoonBit平台最新动态速递 Vol.20
-- 更新目录 --
1/ 支持使用 type
关键字定义 newtype
2/ 支持内联 Wasm 指令
3/ 改进自动分号插入
4/ 字符串插值现在支持Unicode
5/ 优化字符串高亮
6/ 内置类型改进
MoonBit 更新
例如:
type MyInt Int derive(Show)
fn init {
let x = MyInt::MyInt(5)
println(x) // Output: MyInt(5)
println(x.0) // Output: 5
}
2. 支持内联 Wasm 指令
例如:
fn char_to_string(c: Char) -> String =
"(func $char_to_string (param $c i32) (result (ref $moonbit.string)) (array.new $moonbit.string (local.get $c) (i32.const 1)))"
fn init {
receiver
.method1()
.method2()
.method3()
}
fn init {
let record = {
x: 1,
y: "abc" // 以前这里必须加逗号
}
function(
arg1,
arg2 // 以前这里必须加逗号
)
}
4. 字符串插值现在支持Unicode
例如:
let s = "string interpolate unicode \( 中文 )"
修改前:
修改后:
6. 内置类型改进
- 字符串
添加 String::make
fn init {
let s = String::make(3, 'a')
println(s) // Output: aaa
}
修复 String::compare
,修改前 String::compare
只比较长度,修改后,按照字典序比较
- Bytes 和 Buffer
添加Bytes相关函数:
blit
, to_string
, of_string
, sub_string
, blit_from_string
, copy
, set_utf8_char
to_string
, make
, write_string
, write_char
, length
Option
添加Eq/Compare/Show/Default
的默认实现Ref/Array
添加 Show
的默认实现官方平台账号,欢迎扫码关注
MoonBit
知乎|@张宏波 / @MoonBit
小红书|MoonBit月兔
Twitter丨@Moonbitlang
Bilibili丨MoonBit月兔
MoonBit用户交流群|添加小助手moonbit_helper