pub struct EnvExpander<S: EnvSource = StdEnvSource> { /* private fields */ }Expand description
Expands environment variables in strings.
Supported syntax:
${VAR}- Required variable${VAR:-default}- Variable with default value${VAR:?error message}- Required with custom error$VAR- Simple variable reference
Implementations§
Source§impl EnvExpander<StdEnvSource>
impl EnvExpander<StdEnvSource>
Source§impl<S: EnvSource> EnvExpander<S>
impl<S: EnvSource> EnvExpander<S>
Sourcepub fn with_source(source: S) -> Self
pub fn with_source(source: S) -> Self
Create an expander with a custom environment source.
Sourcepub fn expand(&self, input: &str) -> ConnectionResult<String>
pub fn expand(&self, input: &str) -> ConnectionResult<String>
Expand environment variables in a string.
§Examples
use prax_query::connection::EnvExpander;
// SAFETY: This is for documentation purposes only
unsafe { std::env::set_var("PRAX_TEST_HOST", "localhost") };
let expander = EnvExpander::new();
let result = expander.expand("postgres://${PRAX_TEST_HOST}/db").unwrap();
assert_eq!(result, "postgres://localhost/db");
unsafe { std::env::remove_var("PRAX_TEST_HOST") };Sourcepub fn expand_url(&self, url: &str) -> ConnectionResult<String>
pub fn expand_url(&self, url: &str) -> ConnectionResult<String>
Expand a connection URL.
Sourcepub fn has_variables(input: &str) -> bool
pub fn has_variables(input: &str) -> bool
Check if a string contains environment variable references.
Trait Implementations§
Source§impl<S: Clone + EnvSource> Clone for EnvExpander<S>
impl<S: Clone + EnvSource> Clone for EnvExpander<S>
Source§fn clone(&self) -> EnvExpander<S>
fn clone(&self) -> EnvExpander<S>
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<S> Freeze for EnvExpander<S>where
S: Freeze,
impl<S> RefUnwindSafe for EnvExpander<S>where
S: RefUnwindSafe,
impl<S> Send for EnvExpander<S>
impl<S> Sync for EnvExpander<S>
impl<S> Unpin for EnvExpander<S>where
S: Unpin,
impl<S> UnwindSafe for EnvExpander<S>where
S: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)