ROADMAP v0.5.0 - Type casting for static analysis (see ROADMAP.md §7)
(from: &GqlType, to: &GqlType)
| 95 | /// Perform explicit type cast |
| 96 | #[allow(dead_code)] // ROADMAP v0.5.0 - Type casting for static analysis (see ROADMAP.md §7) |
| 97 | pub fn cast(from: &GqlType, to: &GqlType) -> TypeResult<CastOperation> { |
| 98 | if !Self::can_cast(from, to) { |
| 99 | return Err(TypeError::InvalidCast( |
| 100 | format!("{:?}", from), |
| 101 | format!("{:?}", to), |
| 102 | )); |
| 103 | } |
| 104 | |
| 105 | // Same type - no operation needed |
| 106 | if from == to { |
| 107 | return Ok(CastOperation::Identity); |
| 108 | } |
| 109 | |
| 110 | match (from, to) { |
| 111 | // Boolean casts |
| 112 | (GqlType::Boolean, GqlType::String { .. }) => Ok(CastOperation::BooleanToString), |
| 113 | (GqlType::Boolean, to_t) if to_t.is_numeric() => Ok(CastOperation::BooleanToNumeric), |
| 114 | (GqlType::String { .. }, GqlType::Boolean) => Ok(CastOperation::StringToBoolean), |
| 115 | (from_t, GqlType::Boolean) if from_t.is_numeric() => { |
| 116 | Ok(CastOperation::NumericToBoolean) |
| 117 | } |
| 118 | |
| 119 | // Numeric casts |
| 120 | (from_t, to_t) if from_t.is_numeric() && to_t.is_numeric() => { |
| 121 | Ok(CastOperation::NumericCast) |
| 122 | } |
| 123 | (from_t, GqlType::String { .. }) if from_t.is_numeric() => { |
| 124 | Ok(CastOperation::NumericToString) |
| 125 | } |
| 126 | (GqlType::String { .. }, to_t) if to_t.is_numeric() => { |
| 127 | Ok(CastOperation::StringToNumeric) |
| 128 | } |
| 129 | |
| 130 | // Temporal casts |
| 131 | (from_t, to_t) if from_t.is_temporal() && to_t.is_temporal() => { |
| 132 | Ok(CastOperation::TemporalCast) |
| 133 | } |
| 134 | (GqlType::String { .. }, to_t) if to_t.is_temporal() => { |
| 135 | Ok(CastOperation::StringToTemporal) |
| 136 | } |
| 137 | (from_t, GqlType::String { .. }) if from_t.is_temporal() => { |
| 138 | Ok(CastOperation::TemporalToString) |
| 139 | } |
| 140 | |
| 141 | _ => Ok(CastOperation::Custom), |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /// Check if a value satisfies IS TYPED predicate |
| 146 | #[allow(dead_code)] // ROADMAP v0.5.0 - Type casting for static analysis (see ROADMAP.md §7) |
nothing calls this directly
no test coverage detected