Struct countroo::ConfigBuilder
source · pub struct ConfigBuilder { /* private fields */ }
Expand description
ConfigBuilder
- The Architect Behind Your CountRoo
Configuration 🏗️📐
Craft the perfect configuration for your CountRoo
analysis with this builder.
Whether you’re setting up a simple count or gearing up for a deep dive into your project’s
structure, ConfigBuilder
paves the way for a customized analysis experience. Think of it
as laying out the blueprint for CountRoo
’s adventure through your codebase. 🗺️✨
§Features
- Project Path: Direct
CountRoo
to the heart of your project. Whether it’s the root or a specific folder, just set the path, and off you go! 🚀 - Extensions: Specify which file extensions should catch
CountRoo
’s eye. Rust files? Markdown? Configuration files? You decide! 📂👀 - Count Empty Lines: To count or not to count empty lines, that is the question.
With
ConfigBuilder
, the choice is yours. 📄🚫📄
§Usage
Building your Config
is as easy as chaining method calls with ConfigBuilder
. Here’s a
quick example to get you started:
use countroo::prelude::*;
let config = ConfigBuilder::default()
.project_path("src")
.extension("rs")
.count_empty_lines(true)
.build()
.expect("Failed to build the config. Please check your settings!");
With ConfigBuilder
, you’re the master planner behind CountRoo
’s analytical journey.
Set your preferences, build your config, and let the code counting commence! 🎉🔧
Implementations§
source§impl ConfigBuilder
impl ConfigBuilder
sourcepub fn project_path(self, path: &str) -> Self
pub fn project_path(self, path: &str) -> Self
Sets the project path for CountRoo
’s code exploration journey. 🚀🗂️
This method defines the starting point of your project, guiding CountRoo
on where
to begin its analysis. Whether it’s nestled in your project’s root or tucked away in
a subdirectory, point CountRoo
in the right direction, and it’ll happily hop to it.
§Parameters
path
: A string slice (&str
) indicating the path to your project’s source directory. It can be an absolute path or a relative path from the location ofCargo.toml
.
§Behavior
- Relative Paths: If you pass a relative path,
CountRoo
smartly resolves it based on the location of yourCargo.toml
file. It’s like givingCountRoo
a little map. 🗺️ - Absolute Paths: Direct
CountRoo
with confidence if you’ve got an absolute path. It’ll head straight there, no questions asked. 🏃♂️💨
§Returns
Keeps the builder pattern grooving by returning self
, allowing for more method chaining.
§Example Usage
use countroo::prelude::*;
let config = ConfigBuilder::default()
.project_path("src") // Directing to the src directory
.extension("rs") // We're only interested in Rust files
.count_empty_lines(true) // Counting every line, even the empty ones
.build()
.expect("Building config failed. Oh no!");
By setting the project path, you ensure CountRoo
starts its adventure from the
correct location, making your code analysis as accurate and helpful as possible. 🌟
sourcepub fn extension(self, ext: &str) -> Self
pub fn extension(self, ext: &str) -> Self
Adds a single file extension to the list for code analysis consideration. 📄🔍
Tailor CountRoo
’s adventurous path by specifying individual file types it should
pay attention to. Perfect for when you want to focus on just one more extension
without disturbing the existing list. Like inviting just one more friend to your
coding party! 🎉
§Parameters
ext
: A string slice (&str
) representing a single file extension to include in the analysis. Remember, no leading dot (.
) needed!
§Returns
Returns self
, keeping the builder pattern fluent and fabulous. 🔄
§Example Usage
use countroo::prelude::*;
let config = ConfigBuilder::default()
.project_path("/path/to/glorious/project")
.extension("rs") // Just focusing on Rust files here!
.count_empty_lines(true) // Every line counts, even the empty ones!
.build()
.unwrap_or_else(|_| panic!("Failed to build the Config. This is not a drill!"));
By specifying the types of files to analyze, you make CountRoo
’s job both
easier and more aligned with your project’s needs. Let the targeted analysis begin! 🎯🚀
sourcepub fn extensions(self, exts: Vec<&str>) -> Self
pub fn extensions(self, exts: Vec<&str>) -> Self
Adds a list of file extensions to be included in the code analysis. 📁✨
This method allows you to specify which file types CountRoo
should consider
when it embarks on its code counting journey. Whether you’re looking at Rust files,
Markdown documents, or even configuration files, just list their extensions here.
§Parameters
exts
: A vector of string slices (&str
) representing the file extensions to include in the analysis, without the leading dot (.
).
§Returns
Returns self
, enabling the delightful chaining of builder method calls. 🔄
§Example Usage
use countroo::prelude::*;
let config = ConfigBuilder::default()
.project_path("/path/to/project")
.extensions(vec!["rs", "md", "toml"]) // Rustacean essentials!
.count_empty_lines(false) // Skipping those empty lines.
.build()
.expect("Oops! Failed to construct the Config");
Expand your analysis horizon by including a variety of file types,
making CountRoo
your versatile code exploration companion. 🌐🔍
sourcepub fn count_empty_lines(self, count: bool) -> Self
pub fn count_empty_lines(self, count: bool) -> Self
Sets the flag to count (or not count) empty lines in the code analysis. 📝✔️❌
This method configures whether CountRoo
should consider empty lines as part of
its line counting expedition across your project. It’s like choosing whether to
count the spaces between the trees in a forest. 🌳🌲
§Parameters
count
: A boolean value wheretrue
signalsCountRoo
to count every single line, including those sneaky empty ones, andfalse
means skipping over those airy voids.
§Returns
Returns self
, allowing for fluent-style chaining of builder methods. 🔄
§Example Usage
use countroo::prelude::*;
let config = ConfigBuilder::default()
.project_path("/path/to/project")
.extension("rs")
.count_empty_lines(true) // We care about every line, even the empty ones!
.build()
.expect("Config build failed");
Whether your coding style is verbose, with plenty of breathing room, or compact,
with not an empty line in sight, CountRoo
adapts to your preferences. 🎨
sourcepub fn build(self) -> Result<Config, &'static str>
pub fn build(self) -> Result<Config, &'static str>
Builds the Config
object from the builder pattern setup. 🏗️🛠️
Consumes the builder to produce a finalized Config
instance, encapsulating all
the project-specific settings necessary for the CountRoo
analysis. This function
checks that all required fields are set, ensuring the builder is in a valid state
before attempting to construct a Config
object.
§Returns
Ok(Config)
: A shiny newConfig
object ready to guideCountRoo
on its journey 🧭.Err(&'static str)
: A not-so-shiny error message indicating what went wrong during the build process. 😓
§Example Usage
use countroo::prelude::*;
let builder = ConfigBuilder::default()
.project_path("path/to/my/rust/project")
.extension("rs")
.count_empty_lines(true);
let config = builder.build().expect("Failed to build config");
Ensure your project path is set; otherwise, this build will politely refuse to proceed, citing a lack of directions. 🚫🗺️