Skip to main content

io

stdout

import std.io.stdout;

stdout.println("hello, void");
stdout.println("value: {}", x);
stdout.print("no newline");
methoddescription
.println(fmt, ...args)print line with newline
.print(fmt, ...args)print without newline

file io

import std.io.File;

let file = File.open("path/to/file.txt")?;
let content: str = file.read_to_str()?;
file.close();
methoddescription
File.open(path)open file, returns Result[File, str]
.read_to_str()read entire file as string
.write(data)write string to file
.close()close the file handle

http client

import std.io.net.HttpClient as Http;

async fn main(args: Array[str]) uint8 {
let http = Http.new();
let res = http.get("api.example.com/data").await?;
stdout.println("status: {}", res.status);
return 0;
}
methoddescription
Http.new()create new client
.get(url)GET request, returns Async[Response, str]
.post(url, body)POST request