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 askalono::{Store, TextData};
let store = Store::from_cache(File::open("askalono-cache.bin.zstd")?)?;
let result = store.analyze(&TextData::from("what's this"));
Implementations
sourceimpl Store
impl Store
sourcepub fn new() -> Store
pub fn new() -> Store
Create a new Store
.
More often, you probably want to use from_cache
instead of creating
an empty store.
sourcepub fn len(&self) -> usize
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.
sourcepub fn licenses<'a>(&'a self) -> impl Iterator<Item = &String> + 'a
pub fn licenses<'a>(&'a self) -> impl Iterator<Item = &String> + 'a
Get all licenses by name via iterator.
sourcepub fn get_original(&self, name: &str) -> Option<&TextData>
pub fn get_original(&self, name: &str) -> Option<&TextData>
Get a license’s standard TextData by name.
sourcepub fn add_license(&mut self, name: String, data: TextData)
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.
sourcepub fn add_variant(
&mut self,
name: &str,
variant: LicenseType,
data: TextData
) -> Result<(), Error>
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.
sourceimpl Store
impl Store
sourcepub fn from_cache<R>(readable: R) -> Result<Store, Error> where
R: Read + Sized,
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.
sourceimpl Store
impl Store
sourcepub fn load_spdx(
&mut self,
dir: &Path,
include_texts: bool
) -> Result<(), Error>
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
sourceimpl<'de> Deserialize<'de> for Store
impl<'de> Deserialize<'de> for Store
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnwindSafe for Store
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more