Skip to content

Booleans

Boolean has two values: true and false. Combine them with and, or, and not. Conditions must be booleans; numbers and strings are not truthy.

mod booleans
pub fn ready(warm: Boolean, dry: Boolean) -> Boolean {
warm and dry
}
pub fn enabled(manual: Boolean, automatic: Boolean) -> Boolean {
manual or automatic
}
pub fn toggle(value: Boolean) -> Boolean {
not value
}
pub fn label(value: Boolean) -> String {
if value {
"yes"
} else {
"no"
}
}

Comparisons such as count > 0 return a Boolean. An if expression always has an else branch and returns the value of the selected branch. See Matching for exhaustive patterns and multiple conditions.