Struct Store

Source
pub struct Store { /* private fields */ }
Expand description

A representation of a collection of known licenses.

This struct is generally what you want to start with if you’re looking to match text against a database of licenses. Load a cache from disk using from_cache, then use the analyze function to determine what a text most closely matches.

§Examples

use scancode_rust::askalono::{Store, TextData};

let store = Store::from_cache(File::open("askalono-cache.bin.zstd")?)?;
let result = store.analyze(&TextData::from("what's this"));

Implementations§

Source§

impl Store

Source

pub fn analyze<'a>(&'a self, text: &TextData) -> Match<'a>

Compare the given TextData against all licenses in the Store.

This parallelizes the search as much as it can to find the best match. Once a match is obtained, it can be optimized further; see methods on TextData for more information.

Source§

impl Store

Source

pub fn new() -> Store

Create a new Store.

More often, you probably want to use from_cache instead of creating an empty store.

Source

pub fn len(&self) -> usize

Get the number of licenses in the store.

This only counts licenses by name – headers, aliases, and alternates aren’t included in the count.

Source

pub fn is_empty(&self) -> bool

Check if the store is empty.

Source

pub fn licenses(&self) -> impl Iterator<Item = &String>

Get all licenses by name via iterator.

Source

pub fn get_original(&self, name: &str) -> Option<&TextData>

Get a license’s standard TextData by name.

Source

pub fn add_license(&mut self, name: String, data: TextData)

Add a single license to the store.

If the license with the given name already existed, it and all of its variants will be replaced.

Source

pub fn add_variant( &mut self, name: &str, variant: LicenseType, data: TextData, ) -> Result<(), Error>

Add a variant (a header or alternate formatting) of a given license to the store.

The license must already exist. This function cannot be used to replace the original/canonical text of the license.

Source

pub fn aliases(&self, name: &str) -> Result<&Vec<String>, Error>

Get the list of aliases for a given license.

Source

pub fn set_aliases( &mut self, name: &str, aliases: Vec<String>, ) -> Result<(), Error>

Set the list of aliases for a given license.

Source§

impl Store

Source

pub fn from_cache<R>(readable: R) -> Result<Store, Error>
where R: Read + Sized,

Create a store from a cache file.

This method is highly useful for quickly loading a cache, as creating one from text data is rather slow. This method can typically load the full SPDX set from disk in 200-300 ms. The cache will be sanity-checked to ensure it was generated with a similar version of askalono.

Source

pub fn to_cache<W>(&self, writable: W) -> Result<(), Error>
where W: Write + Sized,

Serialize the current store.

The output will be a MessagePack’d gzip’d or zstd’d binary stream that should be written to disk.

Source§

impl Store

Source

pub fn load_spdx( &mut self, dir: &Path, include_texts: bool, ) -> Result<(), Error>

Fill the store with SPDX JSON data.

This function is very specific to the format of SPDX’s license-list-data repository. It reads all JSON files in the json/details directory and creates entries inside the store for matching.

This is intended to be used during build of askalono, so it’s not available unless the spdx feature is enabled.

include_texts, if true, will keep normalized license text data inside the store. This yields a larger store when serialized, but has the benefit of allowing you to diff your result against what askalono has stored.

Trait Implementations§

Source§

impl Default for Store

Source§

fn default() -> Store

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Store

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Store

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,