surrealguard_syntax/
source.rs1use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
12pub struct SourceId(String);
13
14impl SourceId {
15 pub fn new(id: impl Into<String>) -> Self {
17 Self(id.into())
18 }
19
20 pub fn as_str(&self) -> &str {
22 &self.0
23 }
24}
25
26impl fmt::Display for SourceId {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 f.write_str(&self.0)
29 }
30}
31
32impl From<&str> for SourceId {
33 fn from(value: &str) -> Self {
34 Self::new(value)
35 }
36}
37
38impl From<String> for SourceId {
39 fn from(value: String) -> Self {
40 Self::new(value)
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn source_id_preserves_input_text() {
50 let source = SourceId::new("file:///schema.surql");
51
52 assert_eq!(source.as_str(), "file:///schema.surql");
53 assert_eq!(source.to_string(), "file:///schema.surql");
54 }
55}