#language #values #conversion #boolean #automatic #implicit #typed

weak_true

Similar to the automatic implicit conversion to boolean values in weakly typed languages

6 releases

0.1.5 Jun 2, 2024
0.1.4 May 27, 2024

#495 in Algorithms

Download history 168/week @ 2024-05-21 241/week @ 2024-05-28 24/week @ 2024-06-04

433 downloads per month

MIT license

16KB
401 lines

Similar to the automatic implicit conversion to boolean values in weakly typed languages

type impl
float self is not 0.0 / NaN
integer self != 0
reference / smart pointer inner value impl
raw pointer !self.is_null
Option self.is_some
Result self.is_ok
Poll self.is_ready
str / slice / array !self.is_empty
collections !self.is_empty
unit false
bool self
fn / tuple / char true

Examples

use weak_true::WeakTrue;

assert!("c".weak_true());
assert!('c'.weak_true());
assert!('\0'.weak_true());
assert!([0].weak_true());
assert!((&0 as *const i32).weak_true());
assert!(Some(0).weak_true());

assert!(f64::NAN.weak_false());
assert!(0.0.weak_false());
assert!(0.weak_false());
assert!("".weak_false());
assert!([0; 0].weak_false());

No runtime deps