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, ornewline-configfeatures.) - Extensions: A list of file extensions
CountRooshould consider during its analysis, ensuring nothing important gets overlooked. 📚 - Count Empty Lines: A boolean toggle that dictates whether
CountRoocounts 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: boolImplementations§
Source§impl Config
impl Config
Sourcepub fn from_line_separated_string(
config: &str,
count_empty_lines: bool,
project_path: String,
) -> Result<Config, LocCounterError>
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 forCountRooto explore files of those types.count_empty_lines: A boolean indicating whether to count empty lines within files. This toggles whetherCountRoocounts all lines or just those with content.project_path: The starting point forCountRoo’s adventure, specified as a path to the project’s source directory.
§Returns
Ok(Config): AConfigready to guideCountRooon a tailored exploration, equipped with your specified preferences.Err(LocCounterError): An error detailing what went wrong during theConfigcreation.
§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. 🌟🔍
Sourcepub fn from_str_vec(
extensions: Vec<String>,
count_empty_lines: bool,
project_path: String,
) -> Result<Config, LocCounterError>
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 ofStrings representing the file extensions to be included in the analysis. Think of each extension as a ticket invitingCountRooto 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: AStringspecifying the path to your project’s source directory. This is whereCountRoowill start its journey, binoculars in hand. 🗺️🔭
§Returns
Ok(Config): A fully equippedConfigready to guideCountRooon 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. 🌟🧭
Sourcepub fn builder() -> ConfigBuilder
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<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
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>,
Source§impl PathHelpers for Config
Available on crate features toml-config or json-config or yaml-config or xml-config or newline-config only.
impl PathHelpers for Config
toml-config or json-config or yaml-config or xml-config or newline-config only.fn is_relative_path(path: &str) -> bool
fn find_src_folder() -> Option<PathBuf>
fn from_rel_file_path(rel_path: &str) -> Result<Config, LocCounterError>
fn from_abs_file_path( config_path: &str, project_path: String, ) -> Result<Config, LocCounterError>
impl Eq for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more