Skip to main content

Scope

Struct Scope 

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

The declaration, compiled, with where it came from.

Implementations§

Source§

impl Scope

Source

pub fn compile(declaration: Declaration, origin: Origin, path: &str) -> Self

Compile a declaration read from path (repository-relative, or the share path).

Source

pub fn load(share: &Share, repo: &Repository) -> Result<Self, Error>

Read the repository’s declaration when its manifest names a scope section, otherwise the distribution’s default under the share directory.

Source

pub fn declaration(&self) -> &Declaration

The declaration as read.

Source

pub fn origin(&self) -> Origin

Where the declaration came from.

Source

pub fn path(&self) -> &str

The file the declaration was read from: repository-relative for the repository’s own, the share path for the distribution’s.

Source

pub fn classify_name(&self, path: &str, directory: bool) -> Classification

Judge a repository-relative path by its name alone: the out paths and names, then the in pathspecs. Size and content are not consulted; Scope::classify does. A directory is in when an in pathspec can match beneath it.

use majordomus_cli::scope::{Declaration, Origin, Reason, Scope, Verdict};
use std::path::Path;
let text = "version: 1\nin:\n  - src/**\n  - docs/**\nout:\n  paths: ['.git/', '**/target/']\n  secret:\n    names: ['.env', '*.pem']\n";
let scope = Scope::compile(Declaration::parse(Path::new("s"), text).unwrap(), Origin::Repository, "s");
assert_eq!(scope.classify_name("src/main.rs", false).verdict, Verdict::In);
assert_eq!(scope.classify_name("src/.env", false).reason, Some(Reason::Secret));
assert_eq!(scope.classify_name("src/target/x.rs", false).reason, Some(Reason::Path));
assert_eq!(scope.classify_name("README.md", false).reason, Some(Reason::Undeclared));
assert_eq!(scope.classify_name("docs", true).verdict, Verdict::In);
Source

pub fn classify(&self, root: &Path, path: &str) -> Classification

Judge a repository-relative path by name, then, when it exists as a file the name admits, by size and by the first SNIFF_BYTES of its content. A symlink is judged by name only and reported as not existing: sources are regular files.

Source

pub fn tally(&self, root: &Path, files: &[String]) -> Tally

Every tracked file judged by name and size, counted; the out ones listed with their reason. Content is not read: a binary is caught here only by its name.

Source

pub fn tally_repository( &self, repo: &Repository, source: &dyn DiscoverySource, ) -> Result<(Tally, Vec<Diagnostic>), Error>

The tracked files of the repository, through source, judged: the tally, and a diagnostic for every tracked secret, which is never read and should not be tracked.

Trait Implementations§

Source§

impl Debug for Scope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin for Scope

§

impl UnwindSafe for Scope

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more