temper_std/net/
mod.rs

1use temper_core::AnyValueTrait;
2use temper_core::AsAnyValue;
3use temper_core::Pair;
4mod support;
5pub use support::*;
6pub (crate) fn init() -> temper_core::Result<()> {
7    static INIT_ONCE: std::sync::OnceLock<temper_core::Result<()>> = std::sync::OnceLock::new();
8    INIT_ONCE.get_or_init(| |{
9            Ok(())
10    }).clone()
11}
12struct NetRequestStruct {
13    url: std::sync::Arc<String>, method: std::sync::Arc<String>, body_content: Option<std::sync::Arc<String>>, body_mime_type: Option<std::sync::Arc<String>>
14}
15#[ derive(Clone)] pub struct NetRequest(std::sync::Arc<std::sync::RwLock<NetRequestStruct>>);
16impl NetRequest {
17pub fn post(& self, content__22: impl temper_core::ToArcString, mimeType__23: impl temper_core::ToArcString) {
18    let content__22 = content__22.to_arc_string();
19    let mimeType__23 = mimeType__23.to_arc_string();
20    self.0.write().unwrap().method = std::sync::Arc::new("POST".to_string());
21    self.0.write().unwrap().body_content = Some(content__22.clone());
22    let mut t___50: Option<std::sync::Arc<String>> = self.0.read().unwrap().body_mime_type.clone();
23    self.0.write().unwrap().body_mime_type = t___50.clone();
24}
25pub fn send(& self) -> temper_core::Promise<NetResponse> {
26    return send_request(self.0.read().unwrap().url.clone().clone(), self.0.read().unwrap().method.clone(), self.0.read().unwrap().body_content.clone(), self.0.read().unwrap().body_mime_type.clone());
27}
28pub fn new(url__28: impl temper_core::ToArcString) -> NetRequest {
29    let url__28 = url__28.to_arc_string();
30    let url;
31    let method;
32    let body_content;
33    let body_mime_type;
34    url = url__28.clone();
35    method = std::sync::Arc::new("GET".to_string());
36    body_content = None;
37    body_mime_type = None;
38    let selfish = NetRequest(std::sync::Arc::new(std::sync::RwLock::new(NetRequestStruct {
39                    url, method, body_content, body_mime_type
40    })));
41    return selfish;
42}
43}
44temper_core::impl_any_value_trait!(NetRequest, []);
45pub trait NetResponseTrait: temper_core::AsAnyValue + temper_core::AnyValueTrait + std::marker::Send + std::marker::Sync {
46fn clone_boxed(& self) -> NetResponse;
47fn status(& self) -> i32;
48fn content_type(& self) -> Option<std::sync::Arc<String>>;
49fn body_content(& self) -> temper_core::Promise<Option<std::sync::Arc<String>>>;
50}
51#[ derive(Clone)] pub struct NetResponse(std::sync::Arc<dyn NetResponseTrait>);
52impl NetResponse {
53pub fn new(selfish: impl NetResponseTrait + 'static) -> NetResponse {
54    NetResponse(std::sync::Arc::new(selfish))
55}
56}
57temper_core::impl_any_value_trait_for_interface!(NetResponse);
58impl std::ops::Deref for NetResponse {
59type Target = dyn NetResponseTrait;
60fn deref(& self) -> & Self::Target {
61    & ( * self.0)
62}
63}
64fn sendRequest__16(url__35: impl temper_core::ToArcString, method__36: impl temper_core::ToArcString, bodyContent__37: Option<impl temper_core::ToArcString>, bodyMimeType__38: Option<impl temper_core::ToArcString>) -> temper_core::Promise<NetResponse> {
65let url__35 = url__35.to_arc_string();
66let method__36 = method__36.to_arc_string();
67let bodyContent__37 = bodyContent__37.map(| x | x.to_arc_string());
68let bodyMimeType__38 = bodyMimeType__38.map(| x | x.to_arc_string());
69return panic!();
70}