Port event content to Rust (#19725)

Based on #19708.

This is on the path to porting the entire event class to Rust, as
`event.content` will then return the new Rust class `JsonObject`.

This PR adds a pure Rust `JsonObject` class that is a `Mapping`
representing a json-style object. It uses `serde_json::Value` as its
in-memory representation and `pythonize` for conversion when a field is
looked up on the object.

I'm not thrilled with the name, but couldn't think of a better one.

This also adds `JsonObject` handling to the JSON serialisation functions
we use, as well as to the `freeze(..)` function.

Reviewable commit-by-commit.
This commit is contained in:
Erik Johnston authored and GitHub committed 2026-05-08 14:19:03 +01:00
1 parent 8dbbc4000b
commit c430c16df4
21 files changed
+749 -63

No files matched your search

+2 -2
View File
@@ -265,7 +265,7 @@ class ModuleApiTestCase(BaseModuleApiTestCase):
self.assertEqual(event.type, "m.room.message")
self.assertEqual(event.room_id, room_id)
self.assertFalse(hasattr(event, "state_key"))
self.assertDictEqual(event.content, content)
self.assertDictEqual(dict(event.content), content)
expected_requester = create_requester(
user_id, authenticated_entity=self.hs.hostname
@@ -301,7 +301,7 @@ class ModuleApiTestCase(BaseModuleApiTestCase):
self.assertEqual(event.type, "m.room.power_levels")
self.assertEqual(event.room_id, room_id)
self.assertEqual(event.state_key, "")
self.assertDictEqual(event.content, content)
self.assertDictEqual(dict(event.content), content)
# Check that the event was sent
self.event_creation_handler.create_and_send_nonmember_event.assert_called_with(