diff options
author | Nikodem RabuliĆski <nikodemrabulinski@gmail.com> | 2019-10-06 03:46:14 +0200 |
---|---|---|
committer | Kevin Song <chipbuster@users.noreply.github.com> | 2019-10-05 20:46:14 -0500 |
commit | 06ba22eb5c12c8cc0892261899ed140bbb51c99a (patch) | |
tree | 3137f7ccf6f74dc8a3b404d18f6ef7a2aa56d058 /src/config.rs | |
parent | 044e10de1b1b1821a8108574491f22b8daf48233 (diff) |
refactor: Implement Default for SegmentConfig (#495)
Implements the Default trait for SegmentConfig to clean up construction of empty segments.
Also adds a segment::new() function to ease construction of simple segments.
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 6f5025179..dafbe1beb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -219,6 +219,10 @@ impl<'a> ModuleConfig<'a> for SegmentConfig<'a> { } impl<'a> SegmentConfig<'a> { + pub fn new(value: &'static str) -> Self { + Self { value, style: None } + } + /// Mutably set value pub fn set_value(&mut self, value: &'a str) { self.value = value; @@ -246,6 +250,12 @@ impl<'a> SegmentConfig<'a> { } } +impl Default for SegmentConfig<'static> { + fn default() -> Self { + Self::new("") + } +} + /** Parse a style string which represents an ansi style. Valid tokens in the style string include the following: - 'fg:<color>' (specifies that the color read should be a foreground color) |