pub struct ScopeVocabulary {
pub scopes: Vec<ScopeUse>,
pub sampled: usize,
pub unavailable: Option<String>,
/* private fields */
}Expand description
The vocabulary as observed, with what was observed.
use majordomus_cli::commit::ScopeVocabulary;
// an empty vocabulary knows nothing and says so, rather than guessing
let v = ScopeVocabulary::default();
assert!(!v.knows("anything"));
assert!(v.words().is_empty());Fields§
§scopes: Vec<ScopeUse>Every scope, by how often it is used, then by name. The order is the answer to “which scopes does this repository use”, so it is the order a person reads.
sampled: usizeHow many commits were read to learn it.
Set when git could not be asked; the vocabulary is then empty rather than wrong.
Implementations§
Source§impl ScopeVocabulary
impl ScopeVocabulary
Sourcepub fn learn(&mut self, scope: &str, prefix: &str, commits: usize)
pub fn learn(&mut self, scope: &str, prefix: &str, commits: usize)
Record that commits commits scoped changes under prefix as scope.
derive is how a vocabulary is normally built, from the history. This is the same
association stated directly, for a caller that has the evidence by another route —
and for tests, which must be able to state a history rather than construct one.
use majordomus_cli::commit::ScopeVocabulary;
let mut v = ScopeVocabulary::default();
v.learn("commit", "src/commit", 12);
v.learn("commit", "src/commit", 5);
assert_eq!(v.suggest(&["src/commit/a.rs".into()]).expect("known").commits, 17);Sourcepub fn knows(&self, scope: &str) -> bool
pub fn knows(&self, scope: &str) -> bool
Whether the history has used this scope.
use majordomus_cli::commit::{scopes::ScopeUse, ScopeVocabulary};
let mut v = ScopeVocabulary::default();
v.scopes.push(ScopeUse { scope: "commit".into(), commits: 1, directories: vec![] });
assert!(v.knows("commit"));
assert!(!v.knows("nonesuch"));Sourcepub fn words(&self) -> Vec<String>
pub fn words(&self) -> Vec<String>
The scope words alone, in vocabulary order.
use majordomus_cli::commit::{scopes::ScopeUse, ScopeVocabulary};
let mut v = ScopeVocabulary::default();
v.scopes.push(ScopeUse { scope: "site".into(), commits: 9, directories: vec![] });
assert_eq!(v.words(), vec!["site".to_string()]);Sourcepub fn suggest(&self, paths: &[String]) -> Option<ScopeSuggestion>
pub fn suggest(&self, paths: &[String]) -> Option<ScopeSuggestion>
Which scope these paths belong to, judged by what prior commits did with the same directories.
None when nothing in the history associates any scope with any of these paths —
which is the honest answer for the first commit of a new subsystem, and is better
than the most popular scope in the repository, which is what a tie-break to
frequency would produce.
use majordomus_cli::commit::ScopeVocabulary;
let mut v = ScopeVocabulary::default();
// the deepest association wins over the busiest directory two levels up
v.learn("commit", "apps/cli/src/commit", 12);
v.learn("everything", "apps", 900);
let s = v.suggest(&["apps/cli/src/commit/a.rs".into()]).expect("an association");
assert_eq!(s.scope, "commit");Trait Implementations§
Source§impl Clone for ScopeVocabulary
impl Clone for ScopeVocabulary
Source§fn clone(&self) -> ScopeVocabulary
fn clone(&self) -> ScopeVocabulary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ScopeVocabulary
impl Debug for ScopeVocabulary
Source§impl Default for ScopeVocabulary
impl Default for ScopeVocabulary
Source§fn default() -> ScopeVocabulary
fn default() -> ScopeVocabulary
Source§impl<'de> Deserialize<'de> for ScopeVocabulary
impl<'de> Deserialize<'de> for ScopeVocabulary
Source§fn 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>,
impl Eq for ScopeVocabulary
Source§impl JsonSchema for ScopeVocabulary
impl JsonSchema for ScopeVocabulary
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for ScopeVocabulary
impl PartialEq for ScopeVocabulary
Source§fn eq(&self, other: &ScopeVocabulary) -> bool
fn eq(&self, other: &ScopeVocabulary) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ScopeVocabulary
impl Serialize for ScopeVocabulary
impl StructuralPartialEq for ScopeVocabulary
Auto Trait Implementations§
impl Freeze for ScopeVocabulary
impl RefUnwindSafe for ScopeVocabulary
impl Send for ScopeVocabulary
impl Sync for ScopeVocabulary
impl Unpin for ScopeVocabulary
impl UnsafeUnpin for ScopeVocabulary
impl UnwindSafe for ScopeVocabulary
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.