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

Drop syn proc & quote dep & other id128 refactor #79

Closed
wants to merge 3 commits into from
Closed

Drop syn proc & quote dep & other id128 refactor #79

wants to merge 3 commits into from

Conversation

vilgotf
Copy link
Contributor

@vilgotf vilgotf commented Aug 11, 2021

  • Drop the syn, proc & quote deps by removing the derive feature from serde & manually impl Error instead of with thiserror
  • Id128
    • deprecate try_from_slice in favour of TryFrom<[u8]>
    • deprecate parse_str in favor of FromStr
    • add Id128::from_boot method
    • deprecate get_machine in favor of Id128::from_machine
    • deprecate get_machine_app_specific since it goes against the rust API guidelines (users should call Id128::from_machine()?.app_specific() instead)
    • add as_bytes method
    • impl AsRef<[u8]>, AsRef<OsStr>, From<[u8; 16]>, Copy, Default & Hash
    • added serde test
  • change all deps versions from ^x.y.z to x.y.z as cargo interprets them the same

This PR is to the best of my knowledge backwards compatible

Closes #78

}
}

/// Return this machine unique ID.
#[deprecated(since = "0.3.2", note = "use Id128::from_machine()")]
Copy link
Owner

Choose a reason for hiding this comment

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

This looks like an arbitrary/cosmetic rename. If so, let's not do that. The current naming may look ugly, but it is meant to stick closer to the C sd_id128_* APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current naming may look ugly, but it is meant to stick closer to the C sd_id128_* APIs.

Yeah that was my understanding reading the code too. It's just that the C API is... for C so since this is a Rust lib it should follow rust API guidelines. Keeping C API is confusing

Copy link
Owner

Choose a reason for hiding this comment

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

True... to a certain extent. Keeping some alignment on the names helps a lot with discoverability, that's what I've see from other people/consumers using it.
My rule of thumb is roughly to keep (very similar / identical) names for things that are basically 1:1 ports, and exercise a bit more freedom for things that do not fall in that bucket. Here the former applies though.

Copy link
Contributor Author

@vilgotf vilgotf Aug 11, 2021

Choose a reason for hiding this comment

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

Then we can keep the name (get_machine()) but still stick it onto the Id128 struct. By not having free functions we can in 0.4 hide the id128 module and just reexport the Id128 struct. API ref

0.3: libsystemd::id128::get_machine()
0.4 libsystemd::Id128::get_machine()

Looking at https://github.com/coreos/zincati/blob/10a9c409013364697146ff5bf43c8bdaede347ae/src/identity/mod.rs having the id128 module makes the code much uglier than if all the functions were on the Id128 struct.

src/id128.rs Outdated Show resolved Hide resolved
@lucab
Copy link
Owner

lucab commented Aug 11, 2021

Thanks for the PR. I think it is generally nice, but at the same time I think it got a bit out of hand and dragged in a lot of misc stuff.
I'd suggest to unpack this into multiple commits/PRs so we can separately cover what to land and what to rework.

}

/// Return the unique boot ID.
pub fn from_boot() -> Result<Self, SdError> {
Copy link
Owner

Choose a reason for hiding this comment

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

As much as we may not like the original name, this is a port of sd_id128_get_boot(3) so it would be better to align the naming on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling it get_boot would diverge from the Rust method naming scheme. It could just be called boot instead, but from_boot is what the systemd crate named it.

Copy link
Owner

Choose a reason for hiding this comment

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

Indeed that's unfortunate, naming things is hard and aligning multiple beasts even harder. We cowardly refuse to walk into the minefield here and just go with that upstream has, see other comment for the rationale.

This pull request was closed.
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.

Id128 has broken compact serde implementation
2 participants