pub struct EnvVarManager {
pub vars: IndexMap<String, EnvVar>,
pub history: Vec<HistoryEntry>,
}
Fields§
§vars: IndexMap<String, EnvVar>
§history: Vec<HistoryEntry>
Implementations§
Source§impl EnvVarManager
impl EnvVarManager
pub fn new() -> Self
Sourcepub fn load_all(&mut self) -> Result<()>
pub fn load_all(&mut self) -> Result<()>
Loads environment variables from all available sources (process, system, and user).
This method loads environment variables from the current process environment and platform-specific sources like the Windows registry or Unix shell configurations.
§Errors
Returns an error if:
- Registry access fails on Windows platforms
- File system operations fail when reading Unix shell configurations
- Other platform-specific environment variable access fails
pub fn get(&self, name: &str) -> Option<&EnvVar>
Sourcepub fn get_pattern(&self, pattern: &str) -> Vec<&EnvVar>
pub fn get_pattern(&self, pattern: &str) -> Vec<&EnvVar>
Get variables matching a pattern (supports wildcards and regex)
Sourcepub fn get_wildcard(&self, pattern: &str) -> Vec<&EnvVar>
pub fn get_wildcard(&self, pattern: &str) -> Vec<&EnvVar>
Get variables matching a wildcard pattern (* and ?)
Sourcepub fn get_prefix(&self, prefix: &str) -> Vec<&EnvVar>
pub fn get_prefix(&self, prefix: &str) -> Vec<&EnvVar>
Get variables with names starting with a prefix
Sourcepub fn get_suffix(&self, suffix: &str) -> Vec<&EnvVar>
pub fn get_suffix(&self, suffix: &str) -> Vec<&EnvVar>
Get variables with names ending with a suffix
Sourcepub fn get_containing(&self, substring: &str) -> Vec<&EnvVar>
pub fn get_containing(&self, substring: &str) -> Vec<&EnvVar>
Get variables containing a substring (case-insensitive)
Sourcepub fn set(&mut self, name: &str, value: &str, permanent: bool) -> Result<()>
pub fn set(&mut self, name: &str, value: &str, permanent: bool) -> Result<()>
Sets an environment variable with the given name and value.
This method updates the variable both in the manager’s internal state
and in the current process environment. If permanent
is true, it will
also attempt to persist the variable to the system or user environment.
§Errors
Returns an error if:
- Registry operations fail on Windows platforms when setting permanent variables
- File system operations fail when modifying shell configuration files on Unix
- Other platform-specific environment variable persistence operations fail
Sourcepub fn delete(&mut self, name: &str) -> Result<()>
pub fn delete(&mut self, name: &str) -> Result<()>
Deletes an environment variable by name.
This method removes the variable from both the manager’s internal state, the current process environment, and the system environment (if it was a permanent variable).
§Errors
Returns an error if the variable with the given name does not exist.
pub fn list(&self) -> Vec<&EnvVar>
pub fn filter_by_source(&self, source: &EnvVarSource) -> Vec<&EnvVar>
pub fn search(&self, query: &str) -> Vec<&EnvVar>
Sourcepub fn undo(&mut self) -> Result<()>
pub fn undo(&mut self) -> Result<()>
Undoes the last environment variable operation.
This method reverses the most recent operation (set or delete) by restoring the previous state from the history. For set operations, it either restores the previous value or removes the variable if it didn’t exist before. For delete operations, it restores the deleted variable with its previous value.
§Errors
Currently, this method always returns Ok(())
and does not produce errors,
but it returns a Result
for future extensibility and consistency with
other methods in the API.
pub fn clear(&mut self)
Sourcepub fn rename(
&mut self,
pattern: &str,
replacement: &str,
) -> Result<Vec<(String, String)>>
pub fn rename( &mut self, pattern: &str, replacement: &str, ) -> Result<Vec<(String, String)>>
Rename environment variables based on pattern Supports wildcards (*) for batch renaming
§Errors
Returns an error if:
- The pattern contains multiple wildcards (not supported)
- A target variable name already exists when attempting to rename
- The source variable specified by the pattern doesn’t exist (for exact matches)
- System-level operations fail when updating environment variables
Sourcepub fn replace(
&mut self,
pattern: &str,
new_value: &str,
) -> Result<Vec<(String, String, String)>>
pub fn replace( &mut self, pattern: &str, new_value: &str, ) -> Result<Vec<(String, String, String)>>
Replace the value of environment variables matching a pattern
§Arguments
pattern
- Variable name pattern (supports wildcards with *)new_value
- The new value to set
§Errors
Returns an error if:
- The pattern contains multiple wildcards (not supported)
- System-level operations fail when updating environment variables
Sourcepub fn find_replace(
&mut self,
search: &str,
replacement: &str,
pattern: Option<&str>,
) -> Result<Vec<(String, String, String)>>
pub fn find_replace( &mut self, search: &str, replacement: &str, pattern: Option<&str>, ) -> Result<Vec<(String, String, String)>>
Find and replace text within environment variable values
§Arguments
search
- Text to search for in valuesreplacement
- Text to replace withpattern
- Optional variable name pattern to limit the search (supports wildcards)
§Errors
Returns an error if:
- The pattern contains multiple wildcards (not supported)
- System-level operations fail when updating environment variables
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EnvVarManager
impl RefUnwindSafe for EnvVarManager
impl Send for EnvVarManager
impl Sync for EnvVarManager
impl Unpin for EnvVarManager
impl UnwindSafe for EnvVarManager
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more