Skip to main content

VbaProject

Struct VbaProject 

Source
pub struct VbaProject {
    pub project_id: String,
    pub modules: Vec<VbaModule>,
    pub raw_donor: Vec<u8>,
    pub seed_prefix_bytes: Vec<u8>,
    pub seed_module_cookie: u16,
    pub protection_lines: Option<String>,
}
Expand description

A workbook’s VBA project: its modules plus the raw material needed to patch (not rebuild from scratch) a vbaProject.bin on export.

Fields§

§project_id: String

Project ID GUID, e.g. "{7B4E3A2C-1F5D-4A6B-9C8E-2D3F4A5B6C7D}". Must stay internally consistent with protection_lines – never mutated after import/creation, so it always is. If CMG/DPB/GC protection-state lines are ever made independently settable, they must correspond to this exact ID or Excel reports the whole project “unviewable” (a real finding from the POC, not a hypothetical).

§modules: Vec<VbaModule>

The project’s modules, in no particular order. Names are unique case-insensitively.

§raw_donor: Vec<u8>

The full original vbaProject.bin bytes this project was imported from, or (for a project created fresh in this session) vba_synth::synthetic_raw_donor()’s from-scratch bytes – export’s patch base. See vba_xlsx.rs.

§seed_prefix_bytes: Vec<u8>

P-code prefix bytes to donate to the first module ever added to a project that started with none – kept separate from modules rather than as a phantom placeholder module, so it never shows up in list_vba_modules/export. Once a project has at least one real module, new modules instead borrow prefix bytes from an existing one, and this field goes unused.

§seed_module_cookie: u16

VbaModule::module_cookie to donate to the first module ever added to a project that started with none – same donation scheme as seed_prefix_bytes, see there for why.

§protection_lines: Option<String>

The donor’s original PROJECT stream CMG=/DPB=/GC= lines (joined with \r\n), reproduced verbatim on export – None for a project created fresh in this session, which never had any. See vba_xlsx::build_project_stream for why these must be preserved rather than dropped.

Implementations§

Source§

impl VbaProject

Source

pub fn new_empty() -> Self

A brand-new, empty VBA project with no real Excel-authored file behind it anywhere – raw_donor and seed_prefix_bytes are built by vba_synth entirely from scratch. See vba_synth’s doc comment for why that’s now possible.

Source

pub fn find_module(&self, name: &str) -> Option<&VbaModule>

Finds a module by name, matched case-insensitively as VBA does.

Source

pub fn find_module_mut(&mut self, name: &str) -> Option<&mut VbaModule>

Source

pub fn module_name_taken(&self, name: &str) -> bool

Whether a module of this name already exists, matched case-insensitively.

Source

pub fn check_modules(&self) -> Vec<(String, Result<ModuleSyntax, Error>)>

Checks every module, resolving names against the whole project.

This is the check to prefer wherever the project is in hand. VbaModule::check_syntax sees one module and so has to accept any name it cannot resolve, since a sibling may declare it; here the siblings are known, so x = arr(1) with no arr anywhere is reported the way Excel reports it – Excel compiles a project, not a file.

Returns one entry per module, in modules order, pairing the module’s name with its result. A module whose source does not parse still contributes whatever names it declares to the others, since a parse failure in one module is not evidence about another.

Source

pub fn check_modules_partial( &self, ) -> Vec<(String, Result<ModuleSyntax, Error>)>

check_modules for a project that is not the whole story – one whose procedures may live in a referenced project this VbaProject does not model.

Modules still resolve against each other; the only thing that changes is that a name resolving nowhere is accepted rather than reported, as in check_syntax_partial. Nothing in a workbook records whether such a reference exists, so this is a caller’s assertion, not something to infer.

Trait Implementations§

Source§

impl Clone for VbaProject

Source§

fn clone(&self) -> VbaProject

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 Debug for VbaProject

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for VbaProject

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for VbaProject

Source§

fn eq(&self, other: &VbaProject) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for VbaProject

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for VbaProject

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V