// Example demonstrating Windjammer Standard Library usage
// === JSON Example ===
use std::json
fn json_example() {
// Parse JSON
let json_str = "{\"name\": \"Alice\", \"age\": 30}"
let value = json.parse(json_str)
match value {
Ok(v) => {
println!("Parsed: {:?}", v)
// Convert back to string
let stringified = json.stringify(&v)
println!("Stringified: {:?}", stringified)
}
Err(e) => println!("Error: {}", e),
}
}
// === File System Example ===
use std::fs
fn fs_example() {
// Write a file
let content = "Hello from Windjammer!"
fs.write("test.txt", content)
// Read it back
let read_content = fs.read_to_string("test.txt")
match read_content {
Ok(s) => println!("Read: {}", s),
Err(e) => println!("Error: {}", e),
}
// Check if file exists
if fs.exists("test.txt") {
println!("File exists!")
// Clean up
fs.remove_file("test.txt")
}
// Directory operations
fs.create_dir_all("test_dir/nested")
fs.remove_dir_all("test_dir")
}
// === HTTP Example (commented out until reqwest is added to dependencies) ===
// use std::http
// fn http_example() {
// // Simple GET request
// let response = http.get("https://api.github.com/users/github")
//
// match response {
// Ok(mut r) => {
// println!("Status: {}", r.status())
// println!("OK: {}", r.ok())
//
// // Get response as text
// match r.text() {
// Ok(body) => println!("Body: {}", body),
// Err(e) => println!("Error reading body: {}", e),
// }
// }
// Err(e) => println!("Request failed: {}", e),
// }
//
// // POST with JSON
// let data = json.parse("{\"name\": \"test\"}")
// if data.is_ok() {
// let post_response = http.post("https://httpbin.org/post", &data.unwrap())
// println!("POST response: {:?}", post_response)
// }
// }
fn main() {
println!("=== Windjammer Standard Library Examples ===\n")
println!("1. JSON Example:")
json_example()
println!("")
println!("2. File System Example:")
fs_example()
println!("")
// println!("3. HTTP Example:")
// http_example()
println!("\n✅ All examples completed!")
}