Skip to main content

Source

Struct Source 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§lang: LANG

The 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>

Source

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.

Source

pub fn with_name(self, name: Option<String>) -> Self

Builder-style setter for Source::name.

Source

pub fn with_preproc_path(self, preproc_path: Option<&'a Path>) -> Self

Builder-style setter for Source::preproc_path.

Source

pub fn with_preproc(self, preproc: Option<Arc<PreprocResults>>) -> Self

Builder-style setter for Source::preproc.

Trait Implementations§

Source§

impl<'a> Clone for Source<'a>

Source§

fn clone(&self) -> Source<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Source<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Source<'a>

§

impl<'a> RefUnwindSafe for Source<'a>

§

impl<'a> Send for Source<'a>

§

impl<'a> Sync for Source<'a>

§

impl<'a> Unpin for Source<'a>

§

impl<'a> UnsafeUnpin for Source<'a>

§

impl<'a> UnwindSafe for Source<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.