pub struct SourceId(/* private fields */);Expand description
Stable identity for a source analyzed by SurrealGuard.
This may be a real file URI, an embedded-query virtual URI, or any adapter-owned identifier. Spans should never travel without a source id.
Implementations§
Source§impl SourceId
impl SourceId
Sourcepub fn new(id: impl Into<String>) -> Self
pub fn new(id: impl Into<String>) -> Self
Wraps an identifier string as a source id.
Examples found in repository?
examples/conformance.rs (line 23)
13fn main() {
14 let path = std::env::args()
15 .nth(1)
16 .expect("usage: conformance <corpus.json>");
17 let raw = std::fs::read_to_string(&path).expect("corpus file readable");
18 let corpus: Vec<String> = parse_json_strings(&raw);
19
20 let mut failures = 0usize;
21 let mut report = String::new();
22 for (index, query) in corpus.iter().enumerate() {
23 let source = surrealguard_syntax::source::SourceId::new(format!("corpus:{index}"));
24 let Ok(parsed) = surrealguard_syntax::parse::parse_source(source, query.as_str()) else {
25 failures += 1;
26 let _ = writeln!(report, "#{index}: parser returned no tree");
27 continue;
28 };
29 if let Some(range) = first_broken_range(parsed.tree().root_node()) {
30 failures += 1;
31 let snippet: String = query[range.clone()].chars().take(60).collect();
32 let context: String = query.chars().take(80).collect();
33 let _ = writeln!(
34 report,
35 "#{index}: ERROR at {range:?}: `{}`\n in: {}",
36 snippet.replace('\n', " "),
37 context.replace('\n', " ")
38 );
39 }
40 }
41
42 print!("{report}");
43 println!(
44 "---\n{failures}/{} corpus entries fail to parse",
45 corpus.len()
46 );
47 if failures > 0 {
48 std::process::exit(1);
49 }
50}Trait Implementations§
Source§impl<'de> Deserialize<'de> for SourceId
impl<'de> Deserialize<'de> for SourceId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for SourceId
Source§impl Ord for SourceId
impl Ord for SourceId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for SourceId
impl PartialOrd for SourceId
impl StructuralPartialEq for SourceId
Auto Trait Implementations§
impl Freeze for SourceId
impl RefUnwindSafe for SourceId
impl Send for SourceId
impl Sync for SourceId
impl Unpin for SourceId
impl UnsafeUnpin for SourceId
impl UnwindSafe for SourceId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more