DocsStandard LibraryStandard Library (stdlib)
Standard Library

Standard Library (stdlib)

Complete API reference for std.math, std.fs, std.io, std.http, std.json, and std.time.

NextViper Standard Library Reference

The NextViper standard library provides zero-overhead, memory-safe modules for system I/O, networking, data serialization, and mathematical computing.


1. Math Module (`std.math`)

nextviper
import std.math

let s = std.math.sin(std.math.PI / 2.0)
let root = std.math.sqrt(144.0)
let rounded = std.math.floor(3.99)
let clamped = std.math.clamp(150, 0, 100) // 100

2. File System (`std.fs`)

nextviper
import std.fs

// Reading files
let content = std.fs.read_to_string("config.json")

// Writing files
std.fs.write_string("output.txt", "NextViper build complete.
")

// File metadata & inspection
if std.fs.exists("dataset.csv") {
    let size = std.fs.file_size("dataset.csv")
    print("File size:", size, "bytes")
}

3. JSON Serialization (`std.json`)

nextviper
import std.json

let payload = {
    "name": "data",
    "version": "1.0.0",
    "authors": ["NextViper Team"]
}

// Encode to JSON string
let json_str = std.json.stringify(payload)

// Parse from JSON string
let decoded = std.json.parse(json_str)
print("Decoded package name:", decoded["name"])

4. HTTP Client & Server (`std.http`)

nextviper
import std.http

// Asynchronous HTTP GET
let response = std.http.get("https://nextviper.nuratix.com/api/v1/health")
print("Status:", response.status_code)
print("Body:", response.body)

// HTTP POST with JSON body
let post_res = std.http.post(
    "https://api.example.com/data",
    headers: {"Content-Type": "application/json"},
    body: std.json.stringify({"query": "tensor"})
)