MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / as_usize_literal

Function as_usize_literal

nodedb-sql/src/coerce.rs:47–53  ·  view source on GitHub ↗

Resolve a `Value` into a `usize` if numeric-shaped. Accepts: - `Value::Number(n, _)` — the typed-parameter and explicit-literal path. - `Value::SingleQuotedString(s)` where `s` parses as `usize` — the UNKNOWN-param bind path (pgwire drivers that send `Type::UNKNOWN`). `Value::DoubleQuotedString` is NOT accepted: with the PostgreSQL dialect double-quoted tokens parse as `Expr::Identifier`, never

(value: &ast::Value)

Source from the content-addressed store, hash-verified

45/// Does not perform saturating or wrapping coercion — values that
46/// overflow `usize` are rejected, not silently truncated.
47pub fn as_usize_literal(value: &ast::Value) -> Option<usize> {
48 match value {
49 ast::Value::Number(n, _) => n.parse::<usize>().ok(),
50 ast::Value::SingleQuotedString(s) => s.parse::<usize>().ok(),
51 _ => None,
52 }
53}
54
55/// Resolve an `Expr::Value` into a `usize` if numeric-shaped. Thin
56/// wrapper that unpacks the `Expr` → `Value` layer so callers reading

Callers 1

expr_as_usize_literalFunction · 0.85

Calls 1

okMethod · 0.45

Tested by

no test coverage detected