summaryrefslogtreecommitdiffstats
path: root/src/segment.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/segment.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/segment.rs')
-rw-r--r--src/segment.rs48
1 files changed, 6 insertions, 42 deletions
diff --git a/src/segment.rs b/src/segment.rs
index 13f527083..200a93b9e 100644
--- a/src/segment.rs
+++ b/src/segment.rs
@@ -6,9 +6,6 @@ use std::fmt;
/// (e.g. The version that software is running).
#[derive(Clone)]
pub struct Segment {
- /// The segment's name, to be used in configuration and logging.
- pub _name: String,
-
/// The segment's style. If None, will inherit the style of the module containing it.
pub style: Option<Style>,
@@ -17,43 +14,15 @@ pub struct Segment {
}
impl Segment {
- /// Creates a new segment with default fields.
- pub fn new(name: &str) -> Self {
- Self {
- _name: name.to_string(),
- style: None,
- value: "".to_string(),
- }
- }
-
- /// Sets the style of the segment.
- ///
- /// Accepts either `Color` or `Style`.
- pub fn set_style<T>(&mut self, style: T) -> &mut Self
- where
- T: Into<Style>,
- {
- self.style = Some(style.into());
- self
- }
-
- /// Check if the segment has a style
- pub fn has_style(&self) -> bool {
- self.style.is_some()
- }
-
- /// Sets the value of the segment.
- pub fn set_value<T>(&mut self, value: T) -> &mut Self
+ /// Creates a new segment.
+ pub fn new<T>(style: Option<Style>, value: T) -> Self
where
T: Into<String>,
{
- self.value = value.into();
- self
- }
-
- /// Gets the value of the segment.
- pub fn get_value(&self) -> &str {
- &self.value
+ Self {
+ style,
+ value: value.into(),
+ }
}
// Returns the ANSIString of the segment value, not including its prefix and suffix
@@ -63,11 +32,6 @@ impl Segment {
None => ANSIString::from(&self.value),
}
}
-
- /// Determines if the segment contains a value.
- pub fn is_empty(&self) -> bool {
- self.value.trim().is_empty()
- }
}
impl fmt::Display for Segment {