summaryrefslogtreecommitdiffstats
path: root/third_party/python/glean_parser/glean_parser/rust.py
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/python/glean_parser/glean_parser/rust.py')
-rw-r--r--third_party/python/glean_parser/glean_parser/rust.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/third_party/python/glean_parser/glean_parser/rust.py b/third_party/python/glean_parser/glean_parser/rust.py
index eb3355e382..6dd4426d84 100644
--- a/third_party/python/glean_parser/glean_parser/rust.py
+++ b/third_party/python/glean_parser/glean_parser/rust.py
@@ -65,7 +65,7 @@ def rust_datatypes_filter(value):
elif isinstance(value, metrics.CowString):
yield f'::std::borrow::Cow::from("{value.inner}")'
elif isinstance(value, str):
- yield f'"{value}".into()'
+ yield f"{json.dumps(value)}.into()"
elif isinstance(value, metrics.Rate):
yield "CommonMetricData("
first = True
@@ -115,6 +115,11 @@ def type_name(obj):
return "{}<{}>".format(class_name(obj.type), generic)
+ generate_structure = getattr(obj, "_generate_structure", [])
+ if len(generate_structure):
+ generic = util.Camelize(obj.name) + "Object"
+ return "{}<{}>".format(class_name(obj.type), generic)
+
return class_name(obj.type)
@@ -133,6 +138,21 @@ def extra_type_name(typ: str) -> str:
return "UNSUPPORTED"
+def structure_type_name(typ: str) -> str:
+ """
+ Returns the corresponding Rust type for structure items.
+ """
+
+ if typ == "boolean":
+ return "bool"
+ elif typ == "string":
+ return "String"
+ elif typ == "number":
+ return "i64"
+ else:
+ return "UNSUPPORTED"
+
+
def class_name(obj_type):
"""
Returns the Rust class name for a given metric or ping type.
@@ -190,6 +210,7 @@ def output_rust(
("camelize", util.camelize),
("type_name", type_name),
("extra_type_name", extra_type_name),
+ ("structure_type_name", structure_type_name),
("ctor", ctor),
("extra_keys", extra_keys),
),