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

Missing support for core::net::Ipv4Addr/etc. #376

Open
yanshay opened this issue Nov 13, 2023 · 1 comment
Open

Missing support for core::net::Ipv4Addr/etc. #376

yanshay opened this issue Nov 13, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@yanshay
Copy link

yanshay commented Nov 13, 2023

Deku has support for no_std.
It also supports std::net::Ipv4Addr (and other IP addresses structures).
However, in no_std the std IP addresses structures are replaced with core::net:: IP addresses.
I think it's worth supporting those structure as well for completeness ease of developing structures for both std/no_std targets.

Is there a way to implement this myself in my library?
When I just try to copy the code from Deku and apply it on core::net::Ipv4Addr, rust doesn't allow it because DekuWrite is a foreign trait. Any way to overcome it without replacing the structure with my own Ipv4Addr structure (and then using standard serialization) which then cause complications elsewhere?

This is what I tried:

impl<Ctx> DekuWrite<Ctx> for core::net::Ipv4Addr
where
    u32: DekuWrite<Ctx>,
{
    fn write(&self, output: &mut BitVec<u8, Msb0>, ctx: Ctx) -> Result<(), DekuError> {
        let ip: u32 = (*self).into();
        ip.write(output, ctx)
    }
}

This is the error rust raised:

error[E0210]: type parameter `Ctx` must be used as the type parameter for some local type (e.g., `MyStruct<Ctx>`)
  --> src/lib.rs:24:6
   |
24 | impl<Ctx> DekuWrite<Ctx> for core::net::Ipv4Addr
   |      ^^^ type parameter `Ctx` must be used as the type parameter for some local type
   |
   = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
   = note: only traits defined in the current crate can be implemented for a type parameter

@wcampbell0x2a
Copy link
Collaborator

At first glance, this is related to #226 and #226.

No reason we can't support no_std IpAddr

@wcampbell0x2a wcampbell0x2a added the enhancement New feature or request label Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants