Crates.io | wsd |
lib.rs | wsd |
version | 1.1.1 |
source | src |
created_at | 2022-10-31 03:59:25.532079 |
updated_at | 2022-11-16 06:18:46.308087 |
description | Delivers what simply defined. |
homepage | |
repository | https://github.com/sweihub/wsd |
max_upload_size | |
id | 701869 |
size | 33,474 |
wsd
is an intuitive crate delivers What Simply Defined[dependencies]
wsd = "1.0.0"
use std::collections::HashMap;
use wsd::json::*;
fn main()
{
let mut json = json!{
name: "native json",
style: {
color: "red",
size: 12,
bold: true,
range: null
},
array: [5,4,3,2,1],
vector: vec![1,2,3,4,5],
hashmap: HashMap::from([("a", 1), ("b", 2), ("c", 3)]),
students: [
{name: "John", age: 18},
{name: "Jack", age: 21},
],
};
// Native access
json.style.size += 1;
json.students[0].age += 2;
// Stringify
let text = json.stringify(4);
// Parse
json.hashmap.clear();
if let Err(e) = json.parse(&text) {
println!("error: {}", e);
}
println!("json.hashmap = {:#?}", json.hashmap);
}
fn test() {
wsd::http::get("https://docs.rs/", |data| {
println!("status = {}, data = {}", data.status(), data.text());
});
}
fn test() {
wsd::http::post("https://docs.rs/", "{id: 100}", |data| {
println!("status = {}, data = {}", data.status(), data.text());
});
}
use wsd::http::*;
fn test() {
let mut c = Request::new(Method::POST, "https://docs.rs");
c.gzip(true);
c.timeout(5.0);
c.header("TOKEN", "1234567890");
c.send("{id: 100}", |data| {
println!("Data: {}", data.text());
println!("Headers: {:#?}", data.headers());
});
}
Just a convenient wrapper to rust File, check the return value quickly as we did with C API, don't need to check the Result, and unwrap() etc.
using wsd::fs::*;
fn test() -> i32 {
let mut f = File::new();
if f.open("test.txt", O_CREATE | O_RW) != 0 {
// check the error
println!("Error: {}", f.error());
return -1;
}
let data = "Hello World!";
let n = f.write(data);
if n < 0 {
// write error
}
f.rewind();
let mut buf = [0; 4096];
let n = f.read(&mut buf);
if n > 0 {
// success to read n bytes
}
f.seek(256, SEEK_SET);
f.write("more data");
f.close();
return 0;
}
File::new()
File::open()
File::read()
File::write()
File::close()
File::error()
File::path()
File::seek()
File::position()
File::length()
File::is_none()
O_CREATE
O_TRUNCATE
O_RW
O_READ
O_WRITE
O_APPEND
O_NONBLOCK
SEEK_SET
SEEK_CUR
SEEK_END