1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
mod cookies;
pub use cookies::{AllDecodeError, CookieOptions, SameSite};
pub use urlencoding::FromUrlEncodingError;
use std::collections::HashMap;
use wasm_bindgen::JsCast;
use web_sys::HtmlDocument;
fn document() -> HtmlDocument {
web_sys::window()
.unwrap()
.document()
.unwrap()
.dyn_into::<HtmlDocument>()
.unwrap()
}
fn cookie_string() -> String {
document().cookie().unwrap()
}
fn set_cookie_string(value: &str) {
document().set_cookie(value).unwrap();
}
pub fn all_raw() -> HashMap<String, String> {
cookies::all_raw(&cookie_string())
}
pub fn all() -> Result<HashMap<String, String>, AllDecodeError> {
cookies::all(&cookie_string())
}
pub fn get_raw(name: &str) -> Option<String> {
cookies::get_raw(&cookie_string(), name)
}
pub fn get(name: &str) -> Option<Result<String, FromUrlEncodingError>> {
cookies::get(&cookie_string(), name)
}
pub fn set_raw(name: &str, value: &str, options: &CookieOptions) {
set_cookie_string(&cookies::set_raw(name, value, options));
}
pub fn set(name: &str, value: &str, options: &CookieOptions) {
set_cookie_string(&cookies::set(name, value, options));
}
pub fn delete_raw(name: &str) {
set_cookie_string(&cookies::delete_raw(name));
}
pub fn delete(name: &str) {
set_cookie_string(&cookies::delete(name));
}