pub struct ScanResult<'a, T: ContentType, M: FindingMetadata = NoMetadata> { /* private fields */ }Expand description
The outcome of a Scanner::scan call.
A ScanResult gives read-only access to:
- the
globalVarMapfilled by analyzers, - the tree of content objects visited during the scan
(
root,parent,child,next_sibling), - per-object information (
path,content_type,local), - the
findingsrecorded by analyzers viaContext::add_finding.
The M type parameter is the FindingMetadata
stored on each finding. It defaults to NoMetadata.
The result borrows immutably from the scanner. Copy anything you need to keep out of the result before starting another scan.
Implementations§
Source§impl<'a, T: ContentType, M: FindingMetadata> ScanResult<'a, T, M>
impl<'a, T: ContentType, M: FindingMetadata> ScanResult<'a, T, M>
Sourcepub fn global(&self) -> &VarMap
pub fn global(&self) -> &VarMap
Returns the VarMap populated by analyzers during the scan.
This is the read-only counterpart of Context::global.
Sourcepub fn objects_scanned(&self) -> u32
pub fn objects_scanned(&self) -> u32
Returns the total number of content objects visited by the scan (including the root).
Sourcepub fn root(&self) -> Option<ScanContentHandle>
pub fn root(&self) -> Option<ScanContentHandle>
Returns a handle to the root content object.
Returns None if the scan visited no objects (for instance
because the top-level content was rejected by the
Filter).
Sourcepub fn parent(&self, handle: ScanContentHandle) -> Option<ScanContentHandle>
pub fn parent(&self, handle: ScanContentHandle) -> Option<ScanContentHandle>
Returns the parent of handle, if any.
Returns None for the root or for an invalid/detached handle.
Sourcepub fn next_sibling(
&self,
handle: ScanContentHandle,
) -> Option<ScanContentHandle>
pub fn next_sibling( &self, handle: ScanContentHandle, ) -> Option<ScanContentHandle>
Sourcepub fn child(&self, handle: ScanContentHandle) -> Option<ScanContentHandle>
pub fn child(&self, handle: ScanContentHandle) -> Option<ScanContentHandle>
Returns a handle to the first child of handle, if any.
Iterate the remaining children with
next_sibling.
Sourcepub fn local(&self, handle: ScanContentHandle) -> Option<&VarMap>
pub fn local(&self, handle: ScanContentHandle) -> Option<&VarMap>
Returns the per-object VarMap populated by analyzers.
Returns None if the object never touched
Context::local (its map was never allocated) or if the
handle is invalid.
Sourcepub fn path(&self, handle: ScanContentHandle) -> Option<&str>
pub fn path(&self, handle: ScanContentHandle) -> Option<&str>
Returns the path stored for the object referenced by handle.
This is the interned printable view of
Content::path at the moment the object
was scanned (see ContentPath::as_printable_string).
For a live content object, prefer
ContentPath::as_printable_string
(display) or ContentPath::as_path
(filesystem). Returns None for an invalid handle.
Sourcepub fn content_type(&self, handle: ScanContentHandle) -> Option<T>
pub fn content_type(&self, handle: ScanContentHandle) -> Option<T>
Returns the identified ContentType of handle, if any.
Returns None when the scanner was unable to identify the
object’s type (no matching identifier or all identifiers
rejected it), or for an invalid handle.
Sourcepub fn findings(&self) -> FindigsIterator<'a, T, M> ⓘ
pub fn findings(&self) -> FindigsIterator<'a, T, M> ⓘ
Iterates every Finding recorded during the
scan, in emission order.
Analyzers add findings with Context::add_finding. Each
finding is linked to the object that was current at the time,
so Finding::path / Finding::content_type
resolve against this result’s object tree.
for f in res.findings() {
println!("{} {}", f.finding(), f.path().unwrap_or("?"));
}