MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / parse_float

Function parse_float

crates/expr/src/lib.rs:200–217  ·  view source on GitHub ↗

Parse a floating point literal into an [AlgebraicValue]

(
    literal: &str,
    ty: AlgebraicType,
    to_float: ToFloat,
    to_value: ToValue,
)

Source from the content-addressed store, hash-verified

198
199/// Parse a floating point literal into an [AlgebraicValue]
200fn parse_float<Float, Value, ToFloat, ToValue>(
201 literal: &str,
202 ty: AlgebraicType,
203 to_float: ToFloat,
204 to_value: ToValue,
205) -> anyhow::Result<AlgebraicValue>
206where
207 Float: Into<Value>,
208 ToFloat: FnOnce(&BigDecimal) -> Option<Float>,
209 ToValue: FnOnce(Value) -> AlgebraicValue,
210{
211 BigDecimal::from_str(literal)
212 .ok()
213 .and_then(|decimal| to_float(&decimal))
214 .map(|value| value.into())
215 .map(to_value)
216 .ok_or_else(|| anyhow!("{literal} is not a valid {}", fmt_algebraic_type(&ty)))
217}
218
219/// Parses a source text literal as a particular type
220pub(crate) fn parse(value: &str, ty: &AlgebraicType) -> anyhow::Result<AlgebraicValue> {

Callers 1

parseFunction · 0.85

Calls 3

from_strFunction · 0.85
mapMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…