-
Notifications
You must be signed in to change notification settings - Fork 24
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
Port from eui48 to macaddr #142
Conversation
eui48 has a dependency on the deprecated rustc-serialize package.
Every time I leave this project for a couple of month, the first thing I need to do on return is to fix the CI jobs... Here we go again. |
@milliams could you rebase this patch on master? Otherwise, I don't know how to make Github pick up the updated CI configuration. |
df7f77d
to
e2b9442
Compare
Rebased |
Seems to be an actual failure caused by this patch, see build logs: |
It seems there's some difference in how this package serialises its data. I'll have a look into it. |
As far as I can tell, |
@milliams ouch. Thanks for the investigation. Worst case, we'll need to introduce our own type with the bare minimum features. |
@milliams I've looked a bit into this. While macaddr is not perfect, it does have a FromStr implementation https://docs.rs/macaddr/latest/macaddr/struct.MacAddr6.html#impl-FromStr, which means we can have a custom deserialization function. WDYT? |
That could work. I'll have a quick look at it. I've learned a lot more about Serde since I last looked at this, so I might have a chance :) Certainly the |
714d5ae
to
af8df5c
Compare
For now I've gone the route of implementing a new type which wraps I'm happy to go with another method if you think it's better API-wise. |
@@ -330,6 +329,50 @@ pub struct FixedIp { | |||
pub subnet_id: String, | |||
} | |||
|
|||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default, Ord, PartialOrd, Hash)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI fails because of missing Display (which I think should be the same as to_string())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add impl Display
.
pub struct MacAddress(macaddr::MacAddr6); | ||
|
||
impl MacAddress { | ||
pub fn is_nil(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why you need this if you have Deref
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be needed as the serde line:
...
#[serde(skip_serializing_if = "MacAddress::is_nil")]
pub mac_address: MacAddress,
...
specifies a path to a function, so if I remove the fn is_nil
, then it gives the error:
error[E0599]: no function or associated item named `is_nil` found for struct `MacAddress` in the current scope
--> src/network/protocol.rs:461:35
|
333 | pub struct MacAddress(macaddr::MacAddr6);
| --------------------- function or associated item `is_nil` not found for this struct
...
461 | #[serde(skip_serializing_if = "MacAddress::is_nil")]
| ^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `MacAddress`
The alternative seems to be, annotating the serde field with:
...
#[serde(skip_serializing_if = "macaddr::MacAddr6::is_nil")]
pub mac_address: MacAddress,
...
but I thought avoiding having to leak the underlying type directly was worth it.
This allows us to reimplement the Serialize and Deserialize traits to make use of the hex-style format.
af8df5c
to
511ae0d
Compare
|
||
impl std::fmt::Display for MacAddress { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
write!(f, "{}", self.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been self.0.fmt(f)
, I think, but this works for me
eui48
has a dependency on the deprecatedrustc-serialize
package so convert to usemacaddr
.Fixes #140