Skip to content

add a plist macro - copied from serde_json#143

Open
aluedeke wants to merge 6 commits intoebarnard:masterfrom
aluedeke:plist_macro
Open

add a plist macro - copied from serde_json#143
aluedeke wants to merge 6 commits intoebarnard:masterfrom
aluedeke:plist_macro

Conversation

@aluedeke
Copy link

i copied the json macro from serde and modified it i create plist::Value from json annotation. This is super handy when working with lockdown and usbmuxd messages.

I am relatively new to rust, thus i would appreciate any feedback.

The original macro was copied from here:
https://github.com/serde-rs/json/blob/c4f24f3be29a3d096d3ac7b1d5594777a613ec0d/src/macros.rs

Copy link
Owner

@ebarnard ebarnard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, it looks really useful. Please could you add some tests for the macro (hopefully can be copied from serde_json as well.

@aluedeke
Copy link
Author

aluedeke commented Jul 1, 2024

@ebarnard added tests as well

  • removed support for null
  • fixed support for boolean

// Any Serialize type: numbers, strings, struct literals, variables etc.
// Must be below every other rule.
($other:expr) => {
$crate::to_value(&$other).unwrap()
Copy link
Author

@aluedeke aluedeke Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually requires the serde feature @ebarnard should we put the whole macro behind that the serde feature?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to initially limit this to things that implement Into<Value>. If someone wants to serialise something they can always call to_value on it themselves.

@aluedeke
Copy link
Author

@ebarnard anything else i can do to make it easier to merge this?

Copy link
Owner

@ebarnard ebarnard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Sorry this took me so long to get round to looking at. I think it looks good to go barring a few nits.

// Any Serialize type: numbers, strings, struct literals, variables etc.
// Must be below every other rule.
($other:expr) => {
$crate::to_value(&$other).unwrap()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to initially limit this to things that implement Into<Value>. If someone wants to serialise something they can always call to_value on it themselves.

/// });
/// ```
///
/// Variables or expressions can be interpolated into the PList literal. Any type
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Variables or expressions can be interpolated into the literal"? There are no nice casings of "plist".

@@ -0,0 +1,288 @@
/// Construct a `plist::Value` from a JSON literal.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Construct a plist::Value from a JSON-like literal."? As some things will serialise differently to JSON.

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