v0.9.0
Language
- Add
interface
support. - Add
navi fmt
to format code, and install the VS Code extension. - Add
loop
statement to loop forever. - Add getter, and setter to built-in type.
- Add dotenv support, now will auto load
.env
file in the current directory as environment variables. - Add
if let
statement. - Add
main
function, nownavi run
will run themain
function inmain.nv
file in default. - Add httpbin feature into
testharness
to speedup HTTP test.
Stdlib
- Add
resize
,truncate
,split_off
,chunks
method to array. - Add
weekday
tostd.time
. - Add
std.process
withexit
,abort
,pid
,exec
,run
,args
function. - Add
std.json
,std.yaml
,std.querystring
modules for JSON, YAML, QueryString parse, and stringify. - Add
std.value
module to common value type. - Add
basic_auth
method to HTTPRequest
. - Add
chunk
method to HTTPResponse
. - Add
multipart
,form
,timeout
tohttp.Request
. - Add
read
,read_string
tofs.File
, andread
,read_string
tofs
module. - Add
std.io.stdin
,std.io.stdout
,std.io.stderr
. - Add
join
tostd.url
. - Add
std.env.vars
to get all vars.
Breaking Changes
- Rewrite string interpolation from
{1 + 2}
to${1 + 2}
like JavaScript. - Kw Arguments now use
:
instead of=
, e.g.:fn(a: 1, b: 2)
, no longer allowed to be passed positionally. - Most struct get method in stdlib now is getter, e.g.:
host
instead ofhost()
forurl.URL
. - Rename
fs.read_string
tofs.read_to_string
. - Rename
io.from_bytes
toio.new_bytes_from_array
. - Move
cwd
,chdir
fromstd.path
tostd.env
.
Examples
Interface
Like Go, you can define an interface in the following way:
interface Readable {
fn read(): string
}
fn read(r: Readable): string {
return r.read()
}
struct File {
path: string
}
impl File {
fn read(): string {
return "read file"
}
}
struct Body {
content: string
}
impl Body {
fn read(): string {
return "read body"
}
}
fn main() {
file := File{path: "file"}
body := Body{content: "body"}
println(read(file))
println(read(body))
}
If let
use std.io;
fn main() {
let name: string? = "Navi";
if let name = name {
io.println("name is ${name}")
} else {
io.println("name is nil");
}
}