#[non_exhaustive]pub struct Source<'a> { /* private fields */ }Expand description
In-memory source bundle handed to analyze.
Source decouples the display name of the top-level
FuncSpace (Source::name) from the optional filesystem path
used by the C++ preprocessor lookup (Source::preproc_path). For
in-memory snippets, code fetched over the network, or test
fixtures, callers pass Source directly without manufacturing a
Path.
Marked #[non_exhaustive] so future input fields can land
additively. Downstream callers must construct via
Source::new plus the with_* builder setters rather than
struct-literal syntax (rustc rejects external struct literals on
non-exhaustive types with E0639).
§Examples
Analysing an in-memory snippet with no on-disk path:
use big_code_analysis::{analyze, MetricsOptions, Source, LANG};
let source = Source::new(LANG::Rust, b"fn main() {}")
.with_name(Some("snippet.rs".to_owned()));
let space = analyze(source, MetricsOptions::default()).unwrap();
assert_eq!(space.name.as_deref(), Some("snippet.rs"));Implementations§
Source§impl<'a> Source<'a>
impl<'a> Source<'a>
Sourcepub fn new(lang: LANG, code: &'a [u8]) -> Self
pub fn new(lang: LANG, code: &'a [u8]) -> Self
Build a Source for lang and code with no name and no
preprocessor inputs. Chain with_* setters to attach a
display name or preprocessor results.
Source is #[non_exhaustive], so external callers cannot
use struct-literal syntax — this constructor plus the
builder setters are the supported construction path.
Sourcepub fn from_bytes(lang: LANG, code: Vec<u8>) -> Self
pub fn from_bytes(lang: LANG, code: Vec<u8>) -> Self
Build a Source that owns code, so Ast::parse moves the
buffer into the parser instead of copying it. Prefer this over
Source::new when you already hold an owned Vec<u8> (e.g. a
just-read file), which saves one full-buffer copy per parse.
Sourcepub fn with_preproc_path(self, preproc_path: Option<&'a Path>) -> Self
pub fn with_preproc_path(self, preproc_path: Option<&'a Path>) -> Self
Builder-style setter for Source::preproc_path.
Sourcepub fn with_preproc(self, preproc: Option<Arc<PreprocResults>>) -> Self
pub fn with_preproc(self, preproc: Option<Arc<PreprocResults>>) -> Self
Builder-style setter for Source::preproc.