#[non_exhaustive]pub struct Source<'a> {
pub lang: LANG,
pub code: &'a [u8],
pub name: Option<String>,
pub preproc_path: Option<&'a Path>,
pub preproc: Option<Arc<PreprocResults>>,
}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). The
older path-positional entry points (get_function_spaces,
metrics_with_options) conflate the two and derive the name via
lossy UTF-8 conversion of the path; for in-memory snippets, code
fetched over the network, or test fixtures, callers can now 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"));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.lang: LANGThe source language used to select the parser.
code: &'a [u8]Raw source bytes. Source borrows them so callers retain
ownership; analyze copies into the parser’s owned buffer.
name: Option<String>Display / identifier name for the top-level FuncSpace.
If None, the top-level FuncSpace::name is left None.
preproc_path: Option<&'a Path>Optional path used only by the C++ preprocessor lookup
(get_fake_code) to resolve macro definitions in
PreprocResults. For non-C++ languages this is ignored.
Defaults to None.
preproc: Option<Arc<PreprocResults>>Preprocessor results paired with Source::preproc_path.
Same shape as the pr arg on the deprecated entry points.
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 with_name(self, name: Option<String>) -> Self
pub fn with_name(self, name: Option<String>) -> Self
Builder-style setter for Source::name.
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.