1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! # Boolean Logic Common Utilities
//!
//! Shared utilities for boolean logic nodes, including type conversion functions.
use Any;
use Arc;
/// Converts a value to a boolean, supporting common types that can be evaluated as booleans.
///
/// This function attempts to convert various types to boolean values:
/// - `bool`: Returns the value directly
/// - `i32`, `i64`: Returns `true` if non-zero, `false` if zero
/// - `String`: Returns `true` if non-empty, `false` if empty
///
/// # Arguments
///
/// * `value` - The value to convert, wrapped in `Arc<dyn Any + Send + Sync>`
///
/// # Returns
///
/// `Ok(bool)` if conversion succeeds, or `Err(String)` with an error message if the type
/// cannot be converted to boolean.
///
/// # Examples
///
/// ```rust,no_run
/// use streamweave::nodes::boolean_logic::common::to_bool;
/// use std::sync::Arc;
/// use std::any::Any;
///
/// // Convert boolean
/// let bool_val = Arc::new(true) as Arc<dyn Any + Send + Sync>;
/// assert_eq!(to_bool(&bool_val).unwrap(), true);
///
/// // Convert integer
/// let int_val = Arc::new(5i32) as Arc<dyn Any + Send + Sync>;
/// assert_eq!(to_bool(&int_val).unwrap(), true);
///
/// // Convert string
/// let str_val = Arc::new("hello".to_string()) as Arc<dyn Any + Send + Sync>;
/// assert_eq!(to_bool(&str_val).unwrap(), true);
/// ```
/// Zero-copy boolean conversion - only clones Arc references, never the data.