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

implement Signature and Marshal for params::Variant #90

Merged
merged 1 commit into from
Feb 18, 2024

Conversation

MaxVerevkin
Copy link
Contributor

My usecase: I was implementing org.freedesktop.DBus.Properties.GetAll which returns a{sv}. In Rust's types that would be HashMap<&str, Variant>, but I couldn't use it because of the missing impls. Container::make_dict_ref("s", "v", ...) works, but not nearly as ergonomic and forces to go through push_old_param instead of the new push_param.

I did not implement Unmarshal, because I didn't need it yet. Let me know it I should add it too for completeness.

@KillingSpark
Copy link
Owner

I'd like to have a test that covers this in src/tests/verify_marshalling.rs. There is a verify_variant_marshalling test at the end where you can add a codeblock for this codepath. Doesn't have to be extensive but having something there that breaks when something becomes obviously wrong in the future is nice.

If it's not too much trouble I'd like a unmarshal implementation too.

@KillingSpark
Copy link
Owner

Is there a reason not to use the trait based Variant (now that it's actually usable)? No reason not to have this but I wanted to discourage the params based API but I wasn't sure if there are cases they cover the trait based API doesn't

@MaxVerevkin
Copy link
Contributor Author

MaxVerevkin commented Feb 16, 2024

Yes, for org.freedesktop.DBus.Properties.GetAll I need a dict with arbitrary values. I cannot use the Variant newtype because Variant<Param> doesn't work since Param does not implement the necessary traits (and it cannot implement them because Signature methods are associated functions and not member functions, but the signature of Param is only known at runtime).

@MaxVerevkin
Copy link
Contributor Author

I'd like to have a test that covers this in src/tests/verify_marshalling.rs. There is a verify_variant_marshalling test at the end where you can add a codeblock for this codepath. Doesn't have to be extensive but having something there that breaks when something becomes obviously wrong in the future is nice.

If it's not too much trouble I'd like a unmarshal implementation too.

Will do.

@KillingSpark
Copy link
Owner

for org.freedesktop.DBus.Properties.GetAll I need a dict with arbitrary values

Does a map with Box<dyn Marshal> as values not work?

@MaxVerevkin
Copy link
Contributor Author

Marshal is not object safe

@MaxVerevkin
Copy link
Contributor Author

I wanted to discourage the params based API

BTW, I think this change is moving things in this direction. Instead of using get_param() to get a param and then extracting a variant, you can use the new get::<Variant>().

Does this improve #83?

@MaxVerevkin
Copy link
Contributor Author

Oh, also, even with the new trait-based API, I believe having an enum with all possible dbus types is necessary. At least for receiving variants in args. And sending them...

@KillingSpark
Copy link
Owner

// signature ++ padding ++ 32u8

Sorry to be this nit-picky but the test uses 16u8, otherwise lgtm 👍

@KillingSpark
Copy link
Owner

KillingSpark commented Feb 16, 2024

Oh, also, even with the new trait-based API, I believe having an enum with all possible dbus types is necessary. At least for receiving variants in args. And sending them...

There is the Variant struct that allows you to get the correct type (or a param) from the contents. That should work for these cases I think?

@MaxVerevkin
Copy link
Contributor Author

There is the Variant struct that allows you to get the correct type (or a param) from the contents. That should work for these cases I think?

I actually didn't had a chance to use it yet, will try :)

@KillingSpark KillingSpark merged commit 29fa983 into KillingSpark:master Feb 18, 2024
3 checks passed
@MaxVerevkin MaxVerevkin deleted the variant branch February 18, 2024 12:17
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.

2 participants