rama_http/service/web/endpoint/response/
datastar.rs1use super::{IntoResponse, Script};
2use rama_http_types::{
3 Response,
4 header::{CONTENT_TYPE, HeaderValue},
5};
6
7#[derive(Debug, Clone, Copy)]
8pub struct DatastarScript(Script<&'static str>);
18
19impl Default for DatastarScript {
20 fn default() -> Self {
21 Self(Script(include_str!("./datastar.js")))
22 }
23}
24
25impl DatastarScript {
26 #[inline]
27 #[must_use]
29 pub fn new() -> Self {
30 Default::default()
31 }
32}
33
34impl IntoResponse for DatastarScript {
35 #[inline]
36 fn into_response(self) -> Response {
37 self.0.into_response()
38 }
39}
40
41#[derive(Debug, Clone, Copy)]
42pub struct DatastarSourceMap(&'static str);
52
53impl Default for DatastarSourceMap {
54 fn default() -> Self {
55 Self(include_str!("./datastar.js.map"))
56 }
57}
58
59impl DatastarSourceMap {
60 #[inline]
61 #[must_use]
63 pub fn new() -> Self {
64 Default::default()
65 }
66}
67
68impl IntoResponse for DatastarSourceMap {
69 #[inline]
70 fn into_response(self) -> Response {
71 let mut response = Response::new(self.0.into());
72 response
73 .headers_mut()
74 .insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
75 response
76 }
77}