tauri_plugin_prevent_default/
script.rs1use std::fmt;
2use std::ops::Deref;
3use std::sync::Arc;
4
5#[derive(Clone, Debug)]
7pub struct Script(Arc<str>);
8
9impl Script {
10 #[must_use]
11 pub fn new(script: impl AsRef<str>) -> Self {
12 Self(Arc::from(script.as_ref()))
13 }
14
15 #[must_use]
16 pub fn join(&self, script: impl AsRef<str>) -> Self {
17 let mut buf = String::from(self.0.as_ref());
18 buf.push('\n');
19 buf.push_str(script.as_ref());
20 Self::from(buf)
21 }
22}
23
24impl AsRef<str> for Script {
25 fn as_ref(&self) -> &str {
26 self.0.as_ref()
27 }
28}
29
30impl Deref for Script {
31 type Target = str;
32
33 fn deref(&self) -> &Self::Target {
34 self.0.as_ref()
35 }
36}
37
38impl fmt::Display for Script {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 write!(f, "{}", self.0)
41 }
42}
43
44impl From<&str> for Script {
45 fn from(value: &str) -> Self {
46 Script(Arc::from(value))
47 }
48}
49
50impl From<String> for Script {
51 fn from(value: String) -> Self {
52 Script(Arc::from(value))
53 }
54}