
type 关键字定义 newtypetype MyInt Int derive(Show) fn init { let x = MyInt::MyInt(5) println(x) // Output: MyInt(5) println(x.0) // Output: 5 } 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)))" 不过目前内联 Wasm 指令只支持 wasm-gc 后端
现在 MoonBit 支持下面的链式调用写法:
fn init { receiver .method1() .method2() .method3() } 此外,多行的函数调用和结构体创建不再需要在最后加上逗号了:
fn init { let record = { x: 1, y: "abc" // 以前这里必须加逗号 } function( arg1, arg2 // 以前这里必须加逗号 ) } let s = "string interpolate unicode \( 中文 )" 修改前
修改后
字符串
String::makefn 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
新增 Buffer 类型和相关函数: to_string, make, write_string, write_char, length
Option 添加 Eq/Compare/Show/Default 的默认实现, Ref/Array 添加 Show 的默认实现
1 Leviathann 2023 年 12 月 11 日 感觉强制写 trailing comma 挺好的 |
2 Altar 2023 年 12 月 11 日 via Android 你们是怎么想到在小红书做推广的? |
3 keepRun 2023 年 12 月 12 日 via Android 大力支持 |