Translate types and utilities tests
Some checks failed
Rust API gates / api-gates (push) Has been cancelled
Some checks failed
Rust API gates / api-gates (push) Has been cancelled
This commit is contained in:
@@ -303,6 +303,13 @@ PRIVATE_LAYOUTS = {
|
||||
"T:LibreMetaverse.StructuredData.OSDUri": [("value", "libremetaverse_types::compat::Uri")],
|
||||
"T:LibreMetaverse.Imaging.ManagedImage": [("data", "Vec<u8>")],
|
||||
}
|
||||
VALUE_DERIVES = {
|
||||
"T:LibreMetaverse.Matrix4": "Clone, Copy, Debug",
|
||||
"T:LibreMetaverse.Quaternion": "Clone, Copy, Debug",
|
||||
"T:LibreMetaverse.UUID": "Clone, Copy, Debug, Default",
|
||||
"T:LibreMetaverse.Vector3": "Clone, Copy, Debug",
|
||||
"T:LibreMetaverse.Vector3d": "Clone, Copy, Debug",
|
||||
}
|
||||
def generic_names(item: dict) -> list[str]:
|
||||
return [parameter["name"] for parameter in item.get("generic_parameters", [])]
|
||||
|
||||
@@ -522,6 +529,8 @@ def render_type(item: dict, type_row: dict, member_rows: dict[str, dict[str, str
|
||||
else:
|
||||
fields = [member for member in item["members"] if member["kind"] == "field" and not member.get("static")]
|
||||
private_fields = PRIVATE_LAYOUTS.get(item["doc_id"], [])
|
||||
if derives := VALUE_DERIVES.get(item["doc_id"]):
|
||||
lines.append(f"#[derive({derives})]")
|
||||
if item["doc_id"] == "T:LibreMetaverse.StructuredData.OSD":
|
||||
lines += [
|
||||
"#[non_exhaustive]",
|
||||
|
||||
@@ -170,6 +170,12 @@ SUPPORT_TYPES = {
|
||||
MEMBER_RETURN_OVERRIDES = {
|
||||
"M:LibreMetaverse.Caps.Capabilities": "Vec<String>",
|
||||
}
|
||||
TYPE_USAGE_OVERRIDES = {
|
||||
"LibreMetaverse.DictionaryChangeCallback": (
|
||||
"std::sync::Arc<dyn Fn(libremetaverse::DictionaryEventAction, "
|
||||
"libremetaverse_types::compat::DictionaryEntry) + Send + Sync>"
|
||||
),
|
||||
}
|
||||
TYPE_NAME_OVERRIDES = {
|
||||
"T:LibreMetaverse.LslTools.Error": "LslError",
|
||||
}
|
||||
@@ -419,7 +425,13 @@ def function_bodies(text: str) -> list[str]:
|
||||
def validate_generated_shims() -> None:
|
||||
for path in sorted((ROOT / "crates").glob("*/src/generated*.rs")):
|
||||
text = path.read_text()
|
||||
if re.search(r"#\[derive\([^]]*\bDefault\b", text):
|
||||
default_types = set(
|
||||
re.findall(
|
||||
r"#\[derive\([^]]*\bDefault\b[^]]*\)\]\s*pub struct ([A-Za-z_][A-Za-z0-9_]*)",
|
||||
text,
|
||||
)
|
||||
)
|
||||
if default_types - {"UUID"}:
|
||||
raise ValueError(f"generated shim derives a plausible Default: {path.relative_to(ROOT)}")
|
||||
for body in function_bodies(text):
|
||||
if FAKE_BODY.search(body):
|
||||
@@ -514,7 +526,7 @@ class Mapper:
|
||||
if base in generics or ("." not in base and base.startswith("T")):
|
||||
target = base
|
||||
elif target is None:
|
||||
target = self.resolved.get(base)
|
||||
target = TYPE_USAGE_OVERRIDES.get(base, self.resolved.get(base))
|
||||
if target is None:
|
||||
raise ValueError(f"unresolved referenced type: {value} (base {base})")
|
||||
if mapped_arguments and base not in {
|
||||
|
||||
Reference in New Issue
Block a user