surrealdb_core/sql/
script.rs

1use crate::sql::strand::no_nul_bytes;
2use revision::revisioned;
3use serde::{Deserialize, Serialize};
4use std::fmt::{self, Display, Formatter};
5use std::ops::Deref;
6use std::str;
7
8#[revisioned(revision = 1)]
9#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
10#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
11#[non_exhaustive]
12pub struct Script(#[serde(with = "no_nul_bytes")] pub String);
13
14impl From<String> for Script {
15	fn from(s: String) -> Self {
16		Self(s)
17	}
18}
19
20impl From<&str> for Script {
21	fn from(s: &str) -> Self {
22		Self::from(String::from(s))
23	}
24}
25
26impl Deref for Script {
27	type Target = String;
28	fn deref(&self) -> &Self::Target {
29		&self.0
30	}
31}
32
33impl Display for Script {
34	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
35		Display::fmt(&self.0, f)
36	}
37}