Trait typomania::Package

source ·
pub trait Package: Send + Sync {
    // Required methods
    fn authors(&self) -> &dyn AuthorSet;
    fn description(&self) -> Option<&str>;
    fn shared_authors(&self, other: &dyn AuthorSet) -> bool;
}
Expand description

Common trait that packages must implement to provide common metadata used by checks and corpora.

Note that “author” is simply a string in this data model. However these are represented, these need to be unique within the package ecosystem: registry user names, user IDs, or e-mail addresses would tend to be reasonable candidates to represent an author.

Required Methods§

source

fn authors(&self) -> &dyn AuthorSet

Returns an object that can be used to check if one or more authors own this package.

See the documentation for AuthorSet for more detail, but in most cases, this will be implemented as:

impl Package for MyPackage {
    fn authors(&self) -> &dyn AuthorSet {
        self
    }

    // ...
}

impl AuthorSet for MyPackage {
    fn contains(&self, author: &str) -> bool {
        // ...
    }
}
source

fn description(&self) -> Option<&str>

Returns the package description, if it has one.

This isn’t used by any check shipped by default in typomania, but may be useful for NLP checks: packages that typosquat others will tend to replicate their descriptions, summaries, and/or readmes to confuse their targets further.

source

fn shared_authors(&self, other: &dyn AuthorSet) -> bool

Checks if any authors on the other AuthorSet match any authors on this package.

Implementors§