Skip to main content

BoolVar

Struct BoolVar 

Source
pub struct BoolVar { /* private fields */ }
Expand description

Bind one boolean value.

Implementations§

Source§

impl BoolVar

Source

pub fn new(name: impl Into<VariableName>) -> Self

Build a boolean variable.

Examples found in repository?
examples/service_settings.rs (line 23)
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    }
Source

pub fn default(self, value: bool) -> Self

Provide a fallback value when the variable is missing.

Examples found in repository?
examples/service_settings.rs (line 23)
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    }
Source

pub fn allow_empty(self) -> Self

Parse empty strings instead of treating them as missing.

Source

pub fn sensitive(self, value: bool) -> Self

Mark the value as safe to include in validation details.

Source

pub fn validate<F>(self, validator: F) -> Self
where F: Fn(bool) -> Result<(), ValidationError> + Send + Sync + 'static,

Attach a validation rule.

Trait Implementations§

Source§

impl Binding<bool> for BoolVar

Source§

fn bind<E: Environment>(&self, environment: &E) -> Result<bool, BindError>

Load the value from the given environment.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<B> BindingExt for B

Source§

fn optional(self) -> OptionalVar<Self>

Treat missing or explicitly empty values as None. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.