zeb
05/26/2023, 6:53 PMlazy_static
or once_cell
should work, what behavior were you running into?sirupsen
05/26/2023, 6:54 PMlazy_static
but the key is absent between requestssirupsen
05/26/2023, 6:54 PMlazy_static! {
static ref METADATA_CACHE: Mutex<HashMap<String, CacheValue>> = Mutex::new(HashMap::new());
}
sirupsen
05/26/2023, 6:59 PMsirupsen
05/26/2023, 6:59 PMzeb
05/26/2023, 6:59 PMsirupsen
05/26/2023, 7:02 PMkian
05/26/2023, 7:02 PMsirupsen
05/26/2023, 7:03 PMkian
05/26/2023, 7:11 PMLiberator
05/27/2023, 5:10 PMkian
05/27/2023, 5:12 PMnpx wrangler generate <NEW_PROJECT_NAME> worker-rust
sameerali
05/27/2023, 5:38 PMnpx wrangler@3.0.0 generate cf worker-rust
https://cdn.discordapp.com/attachments/882757739019911219/1112072286049144912/Screenshot_2023-05-27_at_10.37.29_AM.png▾
kian
05/27/2023, 5:40 PMsameerali
05/27/2023, 5:41 PMremote: Repository not found.
https://cdn.discordapp.com/attachments/882757739019911219/1112073154274263151/Screenshot_2023-05-27_at_10.41.24_AM.png▾
kian
05/27/2023, 5:43 PMkian
05/27/2023, 5:44 PMJames
05/27/2023, 5:44 PMnpm init cloudflare@1 my-project worker-rust
James
05/27/2023, 5:45 PMinit
commands unfortunatelyafro_ke
05/28/2023, 8:57 PMworker
to use a 0.2
version for wasm-bindgen
so we can use wasm-bindgen-futures
?
https://cdn.discordapp.com/attachments/882757739019911219/1112484752679768134/image.png▾
afro_ke
05/28/2023, 11:15 PMafro_ke
05/28/2023, 11:15 PMhttps://cdn.discordapp.com/attachments/882757739019911219/1112519446267953203/image.png▾
afro_ke
05/28/2023, 11:15 PMzeb
05/28/2023, 11:45 PMzeb
05/28/2023, 11:45 PMzeb
05/28/2023, 11:46 PM0.4.30
is what we use currentlyalex35mil
12/02/2023, 5:34 PMFormData
for a request body, so I just build a string manually (I don't send any files yet, so it supports only text fields):
rust
pub trait Body: fmt::Debug {
fn content_type(&self) -> String;
fn try_into(&self) -> Result<JsValue, worker::Error>;
}
#[derive(Debug)]
pub struct FormDataBody(HashMap<String, String>);
impl FormDataBody {
const BOUNDARY: &'static str = "X-INSERT-YOUR-BOUNDARY";
pub fn new() -> Self {
Self(HashMap::new())
}
pub fn append(&mut self, key: &str, value: &str) {
self.0.insert(key.to_string(), value.to_string());
}
}
impl Body for FormDataBody {
fn content_type(&self) -> String {
format!("multipart/form-data; boundary={}", Self::BOUNDARY)
}
fn try_into(&self) -> Result<JsValue, worker::Error> {
let mut body = String::new();
for (key, value) in &self.0 {
body.push_str(&format!("--{}\r\n", Self::BOUNDARY));
body.push_str(&format!("Content-Disposition: form-data; name=\"{key}\""));
body.push_str(&format!("\r\n\r\n{value}\r\n"));
}
body.push_str(&format!("--{}--\r\n", Self::BOUNDARY));
Ok(body.into())
}
}