Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zv: check the length of Type::signature for tuples/arrays/maps #470

Open
MaxVerevkin opened this issue Sep 10, 2023 · 1 comment
Open

zv: check the length of Type::signature for tuples/arrays/maps #470

MaxVerevkin opened this issue Sep 10, 2023 · 1 comment

Comments

@MaxVerevkin
Copy link
Contributor

MaxVerevkin commented Sep 10, 2023

This assert fails:

use zvariant::Type;

fn main() {
    let illegal = T256::signature();
    assert!(illegal.len() < 256, "{} >= 256", illegal.len());
}

type T4 = (i32, i32, i32, i32);
type T16 = (T4, T4, T4, T4);
type T64 = (T16, T16, T16, T16);
type T256 = (T64, T64, T64, T64);

panicking during the signature call seems reasonable. Ideally this should be checked statically at compile time, but stable Rust isn't there yet... (although I did some research and it is possible on nightly)

Edit: a "better" const impl: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=dc8231eb9acb269988a86b7e8353dcbf

@zeenix
Copy link
Contributor

zeenix commented Sep 11, 2023

panicking during the signature call seems reasonable.

As the quick solution, yes.

Edit: a "better" const impl: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=dc8231eb9acb269988a86b7e8353dcbf

const generics will make things better for sure. I have a local branch, where I've been preparing a bit for the time when Type::signature can be turned into a const.

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

No branches or pull requests

2 participants