pub struct StringVar { /* private fields */ }Expand description
Bind one required string value.
Implementations§
Source§impl StringVar
impl StringVar
Sourcepub fn new(name: impl Into<VariableName>) -> Self
pub fn new(name: impl Into<VariableName>) -> Self
Build a required string variable.
Examples found in repository?
examples/service_settings.rs (line 16)
14 fn bind<E: Environment>(binder: &Binder<E>) -> Result<Self, envbind::BindError> {
15 Ok(Self {
16 host: binder.bind(&StringVar::new("SERVICE_HOST").default("127.0.0.1"))?,
17 port: binder.bind(
18 &U16Var::new("SERVICE_PORT")
19 .default(8080)
20 .validate(validators::u16_in_range(1, 65_535)),
21 )?,
22 service_name: binder.bind(&StringVar::new("SERVICE_NAME").default("api"))?,
23 tracing_enabled: binder.bind(&BoolVar::new("SERVICE_TRACING").default(false))?,
24 })
25 }Sourcepub fn default(self, value: impl Into<String>) -> Self
pub fn default(self, value: impl Into<String>) -> Self
Provide a fallback value when the variable is missing.
Examples found in repository?
examples/service_settings.rs (line 16)
14 fn bind<E: Environment>(binder: &Binder<E>) -> Result<Self, envbind::BindError> {
15 Ok(Self {
16 host: binder.bind(&StringVar::new("SERVICE_HOST").default("127.0.0.1"))?,
17 port: binder.bind(
18 &U16Var::new("SERVICE_PORT")
19 .default(8080)
20 .validate(validators::u16_in_range(1, 65_535)),
21 )?,
22 service_name: binder.bind(&StringVar::new("SERVICE_NAME").default("api"))?,
23 tracing_enabled: binder.bind(&BoolVar::new("SERVICE_TRACING").default(false))?,
24 })
25 }Sourcepub fn allow_empty(self) -> Self
pub fn allow_empty(self) -> Self
Allow empty strings to pass through.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StringVar
impl !RefUnwindSafe for StringVar
impl Send for StringVar
impl Sync for StringVar
impl Unpin for StringVar
impl UnsafeUnpin for StringVar
impl !UnwindSafe for StringVar
Blanket Implementations§
Source§impl<B> BindingExt for B
impl<B> BindingExt for B
Source§fn optional(self) -> OptionalVar<Self>
fn optional(self) -> OptionalVar<Self>
Treat missing or explicitly empty values as
None. Read moreSource§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
Mutably borrows from an owned value. Read more