Skip to content

Added unsigned integer support (u8, u16, u32, u64) in rs_post.#658

Draft
tanu15-png wants to merge 1 commit intometacall:developfrom
tanu15-png:rs_unsigned_type_support
Draft

Added unsigned integer support (u8, u16, u32, u64) in rs_post.#658
tanu15-png wants to merge 1 commit intometacall:developfrom
tanu15-png:rs_unsigned_type_support

Conversation

@tanu15-png
Copy link
Copy Markdown
Contributor

This PR adds support for u8, u16, u32, and u64 in the rs_port. Since MetaCall does not provide native unsigned integer types, all unsigned integers are mapped to METACALL_LONG, which corresponds to i64, the largest integer type available in MetaCall. The design decisions are as follows:
METACALL_LONG is used for all unsigned types to ensure a consistent and safe internal representation.
Incoming values are converted to i64 first and then range-checked before casting to the target unsigned type.
Negative values are rejected to prevent invalid unsigned conversions.
Overflow beyond the target type’s maximum value is explicitly checked and rejected.
Although smaller types like u8 and u16 could fit into METACALL_SHORT or METACALL_INT, using METACALL_LONG avoids cross-language inconsistencies and simplifies conversion logic.
For u64, full support is limited because METACALL_LONG maps to i64, meaning values above i64::MAX cannot be represented.
for example:
Python integers are received as METACALL_LONG regardless of their size.
Using METACALL_LONG ensures compatibility with Python’s integer model.
Mapping unsigned rust types (u8, u16, u32) to METACALL_LONG avoids mismatches when values originate from Python.

@viferga viferga marked this pull request as draft March 4, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant