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-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
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 forCountRoo
to explore files of those types.count_empty_lines
: A boolean indicating whether to count empty lines within files. This toggles whetherCountRoo
counts 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)
: AConfig
ready to guideCountRoo
on a tailored exploration, equipped with your specified preferences.Err(LocCounterError)
: An error detailing what went wrong during theConfig
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. 🌟🔍
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 ofString
s representing the file extensions to be included in the analysis. Think of each extension as a ticket invitingCountRoo
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
: AString
specifying the path to your project’s source directory. This is whereCountRoo
will start its journey, binoculars in hand. 🗺️🔭
§Returns
Ok(Config)
: A fully equippedConfig
ready to guideCountRoo
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. 🌟🧭
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 PartialEq for Config
impl PartialEq for Config
source§impl PathHelpers for Config
impl PathHelpers for Config
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 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
§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
§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.