pub struct Scanner<'a> { /* private fields */ }detection only.Expand description
A ScanStrategy can be used as a high-level wrapped over a Store’s
analysis logic.
A strategy configured here can be run repeatedly to scan a document for multiple licenses, or to automatically optimize to locate texts within a larger text.
§Examples
use spdx::detection::{scan::Scanner, Store};
let store = Store::new();
// [...]
let strategy = Scanner::new(&store)
.confidence_threshold(0.9)
.optimize(true);
let results = strategy.scan(&"my text to scan".into());Implementations§
Source§impl<'a> Scanner<'a>
impl<'a> Scanner<'a>
Sourcepub fn new(store: &'a Store) -> Self
pub fn new(store: &'a Store) -> Self
Construct a new scanning strategy tied to the given Store.
By default, the strategy has conservative defaults and won’t perform any deeper investigation into the contents of files.
Sourcepub fn with_scan_mode(store: &'a Store, mode: ScanMode) -> Self
pub fn with_scan_mode(store: &'a Store, mode: ScanMode) -> Self
Constructs a scanning strategy with the specified mode
Source§impl Scanner<'_>
impl Scanner<'_>
Sourcepub fn confidence_threshold(self, confidence_threshold: f32) -> Self
pub fn confidence_threshold(self, confidence_threshold: f32) -> Self
Set the confidence threshold for this strategy.
The overall license match must meet this number in order to be
reported. Additionally, if contained licenses are reported in the scan
(when optimize is enabled), they’ll also need to meet this bar.
Set this to 1.0 for only exact matches, and 0.0 to report even the weakest match.
Sourcepub fn shallow_limit(self, shallow_limit: f32) -> Self
pub fn shallow_limit(self, shallow_limit: f32) -> Self
Set a fast-exit parameter that allows the strategy to skip the rest of a scan for strong matches.
This should be set higher than the confidence threshold; ideally close to 1.0. If the overall match score is above this limit, the scanner will return early and not bother performing deeper checks.
This is really only useful in conjunction with optimize. A value of
0.0 will fast-return on any match meeting the confidence threshold,
while a value of 1.0 will only stop on a perfect match.
Sourcepub fn optimize(self, optimize: bool) -> Self
pub fn optimize(self, optimize: bool) -> Self
Indicate whether a deeper scan should be performed.
This is ignored if the shallow limit is met. It’s not enabled by
default, however, so if you want deeper results you should set
shallow_limit fairly high and enable this.
Sourcepub fn max_passes(self, max_passes: u16) -> Self
pub fn max_passes(self, max_passes: u16) -> Self
The maximum number of identifications to perform before exiting a scan of a single text.
This is largely to prevent misconfigurations and infinite loop scenarios, but if you have a document with a large number of licenses then you may want to tune this to a value above the number of licenses you expect to be identified.
Sourcepub fn scan(&self, text: &TextData) -> ScanResult<'_>
pub fn scan(&self, text: &TextData) -> ScanResult<'_>
Scan the given text content using this strategy’s configured preferences.
Returns a ScanResult containing all discovered information.
Auto Trait Implementations§
impl<'a> Freeze for Scanner<'a>
impl<'a> RefUnwindSafe for Scanner<'a>
impl<'a> Send for Scanner<'a>
impl<'a> Sync for Scanner<'a>
impl<'a> Unpin for Scanner<'a>
impl<'a> UnsafeUnpin for Scanner<'a>
impl<'a> UnwindSafe for Scanner<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more