mirror of
https://github.com/Dummi26/mers.git
synced 2025-12-15 19:47:50 +01:00
- Added assume_no_enum() because the Err enum is used at least as often as [] for reporting fails.
- changed substring(a b) behavior from "b is the max length of the resulting string" to "b is the exclusive end index, unless it is negative, in which case its abs() value is the maximum length". - fixed a bug in libs/path - added the http_requests library, which can be used to make very basic GET requests - fixed a bug in the gui library that would mess up button handling - you can now escape comments using a backslash `\`: \// will turn into the literal //, \/* will turn into the literal /*. Useful for URLs (because comments work in string literals). Putting a backslash before a linebreak will also ignore that linebreak (useful in long string literals)
This commit is contained in:
1138
mers_libs/http_requests_v1/Cargo.lock
generated
Normal file
1138
mers_libs/http_requests_v1/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
mers_libs/http_requests_v1/Cargo.toml
Executable file
10
mers_libs/http_requests_v1/Cargo.toml
Executable file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "http_requests_v1"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
mers = { path = "../../mers/" }
|
||||
reqwest = { version = "0.11.16", features = ["blocking"] }
|
||||
95
mers_libs/http_requests_v1/src/main.rs
Executable file
95
mers_libs/http_requests_v1/src/main.rs
Executable file
@@ -0,0 +1,95 @@
|
||||
use mers::{
|
||||
libs::inlib::{MyLib, MyLibTask},
|
||||
script::{
|
||||
val_data::VDataEnum,
|
||||
val_type::{VSingleType, VType},
|
||||
},
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let (mut my_lib, mut run) = MyLib::new(
|
||||
"HTTP requests for MERS".to_string(),
|
||||
(0, 0),
|
||||
"basic HTTP functionality for mers. warning: this is fully single-threaded.".to_string(),
|
||||
vec![(
|
||||
"http_get".to_string(),
|
||||
vec![VSingleType::String.to()],
|
||||
VType {
|
||||
types: vec![
|
||||
VSingleType::String,
|
||||
VSingleType::EnumVariantS(
|
||||
format!("Err"),
|
||||
VType {
|
||||
types: vec![
|
||||
VSingleType::EnumVariantS(
|
||||
format!("ErrBuildingRequest"),
|
||||
VSingleType::String.to(),
|
||||
),
|
||||
VSingleType::EnumVariantS(
|
||||
format!("ErrGettingResponseText"),
|
||||
VSingleType::String.to(),
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
)],
|
||||
);
|
||||
let mut stdin = std::io::stdin().lock();
|
||||
let mut stdout = std::io::stdout().lock();
|
||||
let mut err_general = 0;
|
||||
let mut err_building_request = 0;
|
||||
let mut err_getting_response_text = 0;
|
||||
loop {
|
||||
run = match my_lib.run(run, &mut stdin, &mut stdout) {
|
||||
MyLibTask::None(v) => v,
|
||||
MyLibTask::FinishedInit(v) => {
|
||||
err_general = my_lib.get_enum("Err").unwrap();
|
||||
err_building_request = my_lib.get_enum("ErrBuildingRequest").unwrap();
|
||||
err_getting_response_text = my_lib.get_enum("ErrGettingResponseText").unwrap();
|
||||
v
|
||||
}
|
||||
MyLibTask::RunFunction(f) => {
|
||||
let return_value = match f.function {
|
||||
0 => {
|
||||
// http_get
|
||||
if let VDataEnum::String(url) = &f.args[0].data {
|
||||
match reqwest::blocking::get(url) {
|
||||
Ok(response) => match response.text() {
|
||||
Ok(text) => VDataEnum::String(text).to(),
|
||||
Err(e) => VDataEnum::EnumVariant(
|
||||
err_general,
|
||||
Box::new(
|
||||
VDataEnum::EnumVariant(
|
||||
err_getting_response_text,
|
||||
Box::new(VDataEnum::String(e.to_string()).to()),
|
||||
)
|
||||
.to(),
|
||||
),
|
||||
)
|
||||
.to(),
|
||||
},
|
||||
Err(e) => VDataEnum::EnumVariant(
|
||||
err_general,
|
||||
Box::new(
|
||||
VDataEnum::EnumVariant(
|
||||
err_building_request,
|
||||
Box::new(VDataEnum::String(e.to_string()).to()),
|
||||
)
|
||||
.to(),
|
||||
),
|
||||
)
|
||||
.to(),
|
||||
}
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
f.done(&mut stdout, return_value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user