Struct countroo::Config

source ·
pub struct Config {
    pub project_src_path: String,
    pub config_path: Option<String>,
    pub extensions: Vec<String>,
    pub count_empty_lines: bool,
}
Expand description

Configuration section

Config - The Heart of CountRoo’s Configuration 🖤🔧

Embodies the core settings that guide CountRoo in its quest to analyze your Rust project. Whether you’re diving into TOML, JSON, YAML, XML, or even plain text configurations, Config stands ready to adapt, ensuring CountRoo knows exactly what to look for and where to start.

§Features Overview

  • Project Source Path: Marks the trailhead for CountRoo’s exploration, pointing to your project’s source directory. 🚩
  • Config Path: Optionally specifies the path to an external configuration file, allowing for even more tailored analysis settings. 🗂️ (Enabled with toml-config, json-config, yaml-config, xml-config, or newline-config features.)
  • Extensions: A list of file extensions CountRoo should consider during its analysis, ensuring nothing important gets overlooked. 📚
  • Count Empty Lines: A boolean toggle that dictates whether CountRoo counts those silent, empty lines as part of the total. 📉🚫

§Configuration Flexibility

Enabled with various feature flags, Config can morph to understand different configuration formats, making it a versatile companion for any Rust project setup. Whether you prefer the simplicity of a TOML file, the agility of JSON, or the elegance of YAML, Config is your chameleon. 🦎

§Example Usage

// Assuming `toml-config` feature is enabled
use countroo::prelude::*;
let config = Config::default();

Config is where your CountRoo journey begins, setting the stage for a comprehensive code analysis tailored to your project’s unique landscape. 🌄🔍

Fields§

§project_src_path: String§config_path: Option<String>§extensions: Vec<String>§count_empty_lines: bool

Implementations§

source§

impl Config

source

pub fn from_line_separated_string( config: &str, count_empty_lines: bool, project_path: String ) -> Result<Config, LocCounterError>

Creates a Config from a newline-separated string of file extensions, alongside flags for counting empty lines and specifying the project path. 📝↩️🛠️

This handy method allows for a quick setup of your Config directly from a string, where each line represents a new file extension CountRoo should consider during its exploration. It’s akin to giving CountRoo a list of destinations for its code counting journey, written on a scroll. 📜🗺️

§Parameters
  • config: A string with each line specifying a file extension to include in the analysis. This method treats each line as a separate extension, transforming your string into a ticket for CountRoo to explore files of those types.
  • count_empty_lines: A boolean indicating whether to count empty lines within files. This toggles whether CountRoo counts all lines or just those with content.
  • project_path: The starting point for CountRoo’s adventure, specified as a path to the project’s source directory.
§Returns
  • Ok(Config): A Config ready to guide CountRoo on a tailored exploration, equipped with your specified preferences.
  • Err(LocCounterError): An error detailing what went wrong during the Config creation.
§Example Usage
use countroo::Config;
let config_str = "rs\ncs\ndart\ngo\njs\nts\n";
let custom_config = Config::from_line_separated_string(
    config_str,
    true,
    "path/to/my/project".to_string()
)
.expect("Failed to create a Config from the provided string");

Utilize from_line_separated_string to easily convert a simple string into a complex Config for CountRoo, ensuring your analysis is as detailed or as broad as you wish. 🌟🔍

source

pub fn from_str_vec( extensions: Vec<String>, count_empty_lines: bool, project_path: String ) -> Result<Config, LocCounterError>

Constructs a Config from a vector of file extensions, a flag for counting empty lines, and a project path. 🛠️📋

This method allows you to directly create a Config object from the ground up, specifying exactly which file types CountRoo should keep an eye on, whether to count empty lines, and where to start the code counting expedition. It’s like packing your backpack with just the essentials for a hike through your codebase. 🎒🌲

§Parameters
  • extensions: A vector of Strings representing the file extensions to be included in the analysis. Think of each extension as a ticket inviting CountRoo to consider files of that type. 🎟️
  • count_empty_lines: A boolean flag indicating whether empty lines should be counted as part of the total lines of code. It’s the difference between counting every blade of grass in the field or just the flowers. 🌼🚫🌱
  • project_path: A String specifying the path to your project’s source directory. This is where CountRoo will start its journey, binoculars in hand. 🗺️🔭
§Returns
  • Ok(Config): A fully equipped Config ready to guide CountRoo on its analytical adventure.
  • Err(LocCounterError): An error if something goes awry during the creation process.
§Example Usage
use countroo::prelude::*;
let custom_config = Config::from_str_vec(
    vec!["rs".to_string(), "toml".to_string()],
    true,
    "path/to/my/rust/project".to_string(),
)
.expect("Failed to create custom Config");

With from_str_vec, setting up CountRoo for a tailored code analysis is as straightforward as plotting a course on a map. Just decide where you’re going, what you’re looking for, and whether every little detail counts. 🌟🧭

source

pub fn builder() -> ConfigBuilder

Constructs a new ConfigBuilder to kickstart your CountRoo configuration journey. 🚀🛠️

This function is your gateway to creating a custom Config for CountRoo, allowing you to fluently specify project settings, file extensions to analyze, and whether to count those sneaky empty lines. It’s like giving you the keys to the CountRoo rover; you decide where it goes and what it looks for! 🗝️🔍

§Returns

A fresh ConfigBuilder instance with default settings, ready to be tailored to your project’s needs.

§Example Usage
use countroo::prelude::*;
let my_config_builder = Config::builder()
    .project_path("path/to/my/awesome/project")
    .extension("rs")
    .count_empty_lines(true)
    .build()
    .expect("Could not build config - check your paths and settings!");

Start with builder(), chain your configurations, and build. It’s that simple to prep CountRoo for a code counting adventure tailored just for you! 🌟🛠️

Trait Implementations§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Config

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Config

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Config

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 PartialEq for Config

source§

fn eq(&self, other: &Config) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PathHelpers for Config

source§

impl Eq for Config

source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

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