Struct ScanStrategy

Source
pub struct ScanStrategy<'a> { /* private fields */ }
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 scancode_rust::askalono::{ScanStrategy, Store};

let store = Store::new();
// [...]
let strategy = ScanStrategy::new(&store)
    .confidence_threshold(0.9)
    .optimize(true);
let results = strategy.scan(&"my text to scan".into())?;

Implementations§

Source§

impl<'a> ScanStrategy<'a>

Source

pub fn new(store: &'a Store) -> ScanStrategy<'a>

Construct a new scanning strategy tied to the given Store.

By default, the strategy has conservative defaults and won’t perform any deeper investigaton into the contents of files.

Source

pub fn mode(self, mode: ScanMode) -> Self

Set the scanning mode.

See ScanMode for a description of options. The default mode is Elimination, which is a fast, good general-purpose matcher.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn step_size(self, step_size: usize) -> Self

Configure the scanning interval (in lines) for TopDown mode.

A smaller step size will be more accurate at a significant cost of speed.

Source

pub fn scan(&self, text: &TextData) -> Result<ScanResult<'_>, Error>

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 ScanStrategy<'a>

§

impl<'a> RefUnwindSafe for ScanStrategy<'a>

§

impl<'a> Send for ScanStrategy<'a>

§

impl<'a> Sync for ScanStrategy<'a>

§

impl<'a> Unpin for ScanStrategy<'a>

§

impl<'a> UnwindSafe for ScanStrategy<'a>

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.