pub struct FoamFile {
pub header: Option<FoamHeader>,
pub dict: FoamDict,
}Expand description
A parsed OpenFOAM dictionary file: its FoamFile header (if present) and
the body of entries.
Fields§
§header: Option<FoamHeader>The FoamFile { … } header, or None if the file had none.
dict: FoamDictThe dictionary body.
Implementations§
Source§impl FoamFile
impl FoamFile
Sourcepub fn parse(text: &str) -> Result<Self, IoError>
pub fn parse(text: &str) -> Result<Self, IoError>
Parse dictionary text into a header (if any) and body.
Sourcepub fn parse_named(
text: &str,
context: impl Into<String>,
) -> Result<Self, IoError>
pub fn parse_named( text: &str, context: impl Into<String>, ) -> Result<Self, IoError>
Like Self::parse but labels parse errors with context.
Sourcepub fn read(path: impl AsRef<Path>) -> Result<Self, IoError>
pub fn read(path: impl AsRef<Path>) -> Result<Self, IoError>
Read and parse a dictionary file from path.
#include directives are not followed — use
read_with_includes for that.
Sourcepub fn read_with_includes(path: impl AsRef<Path>) -> Result<Self, IoError>
pub fn read_with_includes(path: impl AsRef<Path>) -> Result<Self, IoError>
Read and parse a dictionary file from path, splicing in any
#include "relative/name" directives first.
OpenFOAM’s #include is a textual include resolved relative to the
including file’s directory, and dictionaries in the wild lean on it —
GeN-Foam’s nuclearData, for instance, puts each reactor state’s zone
data in its own XS… file and includes it inside the zones ( … ) list.
Parsing such a file without following the includes does not fail; it
silently yields a list containing the words #include and XSref, which
is the failure mode this exists to avoid.
This is deliberately a separate entry point rather than a change to
read: following an include reads files the caller did not
name, so it is opt-in.
§Scope and limits
- Only
#include "…"is handled.#includeEtc,#includeFunc,#inputMode,#calcand the other OpenFOAM directives are left in place as ordinary tokens. - Includes nest, to a depth of
MAX_INCLUDE_DEPTH. Exceeding it is an error rather than a hang, which is what a cyclic include would otherwise cause. - The included text is spliced verbatim. An included file carrying its
own
FoamFile { … }header would therefore land mid-body; OpenFOAM behaves the same way, and files meant for inclusion do not carry one.
§Errors
IoError if path or any included file cannot be read, if an
#include is not followed by a quoted filename, or if the include depth
is exceeded.
Sourcepub fn to_foam_string(&self) -> String
pub fn to_foam_string(&self) -> String
Serialise to OpenFOAM ASCII text (banner + header + body).