summaryrefslogtreecommitdiffstats
path: root/src/module.rs
diff options
context:
space:
mode:
authorTilmann Meyer <allescrafterx@gmail.com>2020-08-16 19:16:05 -0700
committerGitHub <noreply@github.com>2020-08-16 22:16:05 -0400
commitbcdf522af57f8146f51ea4dce0e3bc632c7796a4 (patch)
tree150352b23cc04afe92bc5e1166574369a66457d4 /src/module.rs
parent2e14d1af5a3b90aedab39180e0851e8f945b9f55 (diff)
chore: remove unused name from Segment and remove some of the misleading underscores (#1584)
* chore: Remove unused name from Segment and remove some of the misleading underscores * chore: Access members of `Segment` directly
Diffstat (limited to 'src/module.rs')
-rw-r--r--src/module.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/module.rs b/src/module.rs
index e8d40f66e..3aa1cfea2 100644
--- a/src/module.rs
+++ b/src/module.rs
@@ -66,7 +66,7 @@ pub struct Module<'a> {
pub config: Option<&'a toml::Value>,
/// The module's name, to be used in configuration and logging.
- _name: String,
+ name: String,
/// The module's description
description: String,
@@ -80,7 +80,7 @@ impl<'a> Module<'a> {
pub fn new(name: &str, desc: &str, config: Option<&'a toml::Value>) -> Module<'a> {
Module {
config,
- _name: name.to_string(),
+ name: name.to_string(),
description: desc.to_string(),
segments: Vec::new(),
}
@@ -93,7 +93,7 @@ impl<'a> Module<'a> {
/// Get module's name
pub fn get_name(&self) -> &String {
- &self._name
+ &self.name
}
/// Get module's description
@@ -103,12 +103,17 @@ impl<'a> Module<'a> {
/// Whether a module has non-empty segments
pub fn is_empty(&self) -> bool {
- self.segments.iter().all(|segment| segment.is_empty())
+ self.segments
+ .iter()
+ .all(|segment| segment.value.trim().is_empty())
}
/// Get values of the module's segments
pub fn get_segments(&self) -> Vec<&str> {
- self.segments.iter().map(Segment::get_value).collect()
+ self.segments
+ .iter()
+ .map(|segment| segment.value.as_str())
+ .collect()
}
/// Returns a vector of colored ANSIString elements to be later used with
@@ -159,7 +164,7 @@ mod tests {
let desc = "This is a unit test";
let module = Module {
config: None,
- _name: name.to_string(),
+ name: name.to_string(),
description: desc.to_string(),
segments: Vec::new(),
};
@@ -173,9 +178,9 @@ mod tests {
let desc = "This is a unit test";
let module = Module {
config: None,
- _name: name.to_string(),
+ name: name.to_string(),
description: desc.to_string(),
- segments: vec![Segment::new("test_segment")],
+ segments: vec![Segment::new(None, "")],
};
assert!(module.is_empty());