rl_lang/interpreter/stdlib/http/
http_server_stop.rs1use crate::interpreter::{
2 evaluator::Evaluator,
3 stdlib::{
4 common::{extract_number, verr, vnl, vok, vs},
5 http::HttpHandle,
6 },
7 values::Value,
8};
9pub fn func(eval: &mut Evaluator, id: Value) -> Value {
10 let id = match extract_number(id, "http_server_stop") {
11 Ok(a) if a as i64 >= 0 => a as i64,
12 Ok(_) => {
13 return verr!(vs!(
14 "http_server_stop: id handle cannot be negative".to_string()
15 ));
16 }
17 Err(e) => return verr!(vs!(format!("{}", e))),
18 };
19 match eval.http_handles.get(&id) {
20 Some(HttpHandle::Server(_)) => {
21 eval.http_handles.remove(&id);
22 vok!(vnl!())
23 }
24 Some(_) => verr!(vs!(format!(
25 "http_server_stop: handle {} is not a server",
26 id
27 ))),
28 None => verr!(vs!(format!("http_server_stop: unknown handle {}", id))),
29 }
30}