Skip to main content

Crate content_scan

Crate content_scan 

Source
Expand description

§content_scan

A pluggable, hierarchical content-scanning framework.

content_scan provides the building blocks for walking arbitrary content (files, buffers, nested archives, embedded resources, etc.), identifying its type, analyzing it, and recursively extracting inner content. It is intentionally transport-agnostic: the caller supplies anything that implements Content and the Scanner takes care of dispatch, recursion, filtering, and result aggregation.

§Concepts

§Example

ⓘ
use content_scan::*;

#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, ContentType)]
#[repr(u16)]
enum MyTypes { Text }

struct TextId;
impl ContentIdentifier<MyTypes> for TextId {
    fn identify_method(&self) -> Option<IdentifyMethod> {
        Some(IdentifyMethod::Extension("txt"))
    }
    fn validate(&self, _: &mut dyn Content<MyTypes>) -> bool { true }
}

let mut scanner = ScannerBuilder::<MyTypes>::new()
    .add_identifier(MyTypes::Text, TextId)
    .build();

let mut content = BufferContent::<MyTypes>::new(b"hello", "hello.txt");
let result = scanner.scan(&mut content, true);
assert_eq!(result.objects_scanned(), 1);

§Scanning a directory

ⓘ
use content_scan::*;

let mut scanner = ScannerBuilder::<MyTypes>::new()
    .add_extractor(MyTypes::Folder, FolderExtractor::<MyTypes>::new(true, false))
    .build();

let mut root = FolderContent::<MyTypes>::with_content_type("./src", MyTypes::Folder);
// `false`: the root folder itself is not tested against the filter
let result = scanner.scan(&mut root, false);

Macros§

var
Expands a string literal to varmap::Key::new(<fnv1a hash>).

Structs§

BufferContent
An in-memory Content backed by an owned byte buffer.
ContentPath
A path or address identifying a piece of content.
ContentReader
Sequential Read + Seek adapter over an OwnedContentPtr.
Context
Mutable state shared with plugins during a scan.
Entry
Metadata for a single entry produced by a ContentExtractor.
EnumVarMap
Heterogeneous map keyed by an enum implementing EnumVarMapKey.
EnumVarMapPool
Pool of reusable EnumVarMap values keyed by K.
ExtractRequestBuilder
Fluent builder for an extraction request, returned by Context::request_extract.
ExtractionContext
Region of a parent Content that a ContentExtractor should look at, plus optional analyzer-supplied parameters.
FileContent
A Content backed by a file on disk.
Filter
Compiled inclusion/exclusion policy applied to every content item before it is scanned.
FilterBuilder
Builder for a Filter.
FindigsIterator
Iterator over the findings of a ScanResult.
Finding
One finding recorded by an analyzer during a scan.
FolderContent
A Content standing for a directory rather than a byte stream.
FolderExtractor
A ContentExtractor that enumerates the entries of a directory.
Key
Opaque key for VarMap, holding a 64-bit hash.
NoMetadata
Empty metadata type used when findings carry no extra data.
OwnedContentPtr
Non-owning handle to the parent Content of an extraction session.
PoolHandle
Opaque generational handle to a map checked out from a pool.
Readonly
A Sync read-only view of a map, safe to copy onto other threads.
ReadyFilterBuilder
Finalized FilterBuilder ready to produce a Filter.
ScanContentHandle
Opaque handle to a content object inside a ScanResult.
ScanResult
The outcome of a Scanner::scan call.
Scanner
The engine that drives a scan.
ScannerBuilder
Fluent builder for Scanner.
Shared
A thread-safe, cheaply cloneable handle to a map (or any T).
StrVarMap
Heterogeneous map keyed by &str.
StrVarMapPool
Pool of reusable StrVarMap values.
Value
An encoded value and its associated arena borrow.
ValueBuilder
Helper for encoding VarMapValue types into a map arena.
ValueMut
Mutable view over a stored [ValueKind] and its arena.
VarMap
Heterogeneous map keyed by Key.
VarMapPool
Pool of reusable VarMap values.
ZipExtractor
A ContentExtractor that unpacks the members of a ZIP archive.
ZipIdentifier
A ContentIdentifier for ZIP archives.

Enums§

AnalysisOutcome
Return value used by analyzers to steer the scan.
ClearStrategy
Strategy controlling which maps a pool retains when clear is called.
IdentifyMethod
Fast, declarative way to identify a content type without running custom code.
MemAlign
Alignment bucket for data written into a map arena.
Precedence
Precedence of a Filter rule.

Traits§

Content
A byte-addressable piece of content the scanner can operate on.
ContentAnalyzer
A plugin that inspects a piece of content and records information.
ContentExtractor
A plugin that turns a container into a stream of child Content items.
ContentIdentifier
A plugin that classifies content into a ContentType.
ContentReadExt
ContentType
Enumeration of content kinds understood by a scanner.
Dependencies
Debug-only name and required-analyzer list for a plugin.
EnumVarMapKey
Enum key type for EnumVarMap.
ExtractionSession
A live extraction of children from one parent Content.
FindingMetadata
Typed extra data attached to a Finding.
ScanObserver
Callbacks for watching a scan as it runs.
StopCondition
Predicate that can abort a scan early.
VarMapValue
Types that can be stored in and read from a varmap.

Derive Macros§

ContentType
Derives an implementation of content_scan::ContentType for a #[repr(u16)] enum.
Dependencies
Derives an implementation of content_scan::Dependencies.
EnumVarMap
Derives EnumVarMapKey for a unit enum.
VarMapValue
Derives VarMapValue for a Copy struct or enum.