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

Function parse

crates/expr/src/lib.rs:220–370  ·  view source on GitHub ↗

Parses a source text literal as a particular type

(value: &str, ty: &AlgebraicType)

Source from the content-addressed store, hash-verified

218
219/// Parses a source text literal as a particular type
220pub(crate) fn parse(value: &str, ty: &AlgebraicType) -> anyhow::Result<AlgebraicValue> {
221 let to_timestamp = || {
222 Timestamp::parse_from_rfc3339(value)?
223 .serialize(ValueSerializer)
224 .with_context(|| "Could not parse timestamp")
225 };
226 let to_bytes = || {
227 from_hex_pad::<Vec<u8>, _>(value)
228 .map(|v| v.into_boxed_slice())
229 .map(AlgebraicValue::Bytes)
230 .with_context(|| "Could not parse hex value")
231 };
232 let to_identity = || {
233 Identity::from_hex(value)
234 .map(AlgebraicValue::from)
235 .with_context(|| "Could not parse identity")
236 };
237 let to_connection_id = || {
238 ConnectionId::from_hex(value)
239 .map(AlgebraicValue::from)
240 .with_context(|| "Could not parse connection id")
241 };
242 let to_uuid = || {
243 Uuid::parse_str(value)
244 .map(AlgebraicValue::from)
245 .map_err(|err| anyhow!(err))
246 };
247 let to_i256 = |decimal: &BigDecimal| {
248 i256::from_str_radix(
249 // Convert to decimal notation
250 &decimal.to_plain_string(),
251 10,
252 )
253 .ok()
254 };
255 let to_u256 = |decimal: &BigDecimal| {
256 u256::from_str_radix(
257 // Convert to decimal notation
258 &decimal.to_plain_string(),
259 10,
260 )
261 .ok()
262 };
263 match ty {
264 AlgebraicType::I8 => parse_int(
265 // Parse literal as I8
266 value,
267 AlgebraicType::I8,
268 BigDecimal::to_i8,
269 AlgebraicValue::I8,
270 ),
271 AlgebraicType::U8 => parse_int(
272 // Parse literal as U8
273 value,
274 AlgebraicType::U8,
275 BigDecimal::to_u8,
276 AlgebraicValue::U8,
277 ),

Callers 15

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
from_strMethod · 0.85
mainFunction · 0.85
fetch_ws_tokenFunction · 0.85
_type_exprFunction · 0.85
type_insertFunction · 0.85
type_updateFunction · 0.85
type_and_rewrite_setFunction · 0.85

Calls 13

parse_intFunction · 0.85
parse_floatFunction · 0.85
StringClass · 0.85
is_bytesMethod · 0.80
OkFunction · 0.50
to_bytesFunction · 0.50
serializeMethod · 0.45
mapMethod · 0.45
okMethod · 0.45
is_timestampMethod · 0.45
is_identityMethod · 0.45
is_connection_idMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…