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

Can't create IcmpSocketBuffer without heap allocation #181

Closed
steynh opened this issue Mar 23, 2018 · 0 comments
Closed

Can't create IcmpSocketBuffer without heap allocation #181

steynh opened this issue Mar 23, 2018 · 0 comments

Comments

@steynh
Copy link

steynh commented Mar 23, 2018

I would like to create an IcmpSocket without the use of heap, like this:

let icmp_socket = {
    static mut ICMP_RX_DATA: [u8; 256] = [0; 256];
    static mut ICMP_TX_DATA: [u8; 256] = [0; 256];
    static mut ICMP_RX_METADATA: [PacketMetadata<smoltcp::wire::IpAddress>;1] = [IcmpPacketMetadata::empty(); 1];
    static mut ICMP_TX_METADATA: [PacketMetadata<smoltcp::wire::IpAddress>;1] = [IcmpPacketMetadata::empty(); 1];

    let icmp_rx_buffer = IcmpSocketBuffer::new(unsafe { &mut ICMP_RX_METADATA[..] }, unsafe { &mut ICMP_RX_DATA[..] });
    let icmp_tx_buffer = IcmpSocketBuffer::new(unsafe { &mut ICMP_TX_METADATA[..] }, unsafe { &mut ICMP_TX_DATA[..] });

    IcmpSocket::new(icmp_rx_buffer, icmp_tx_buffer)
};

However, I can't seem to make a PacketMetadata buffer without using heap allocation. Because PacketMetadata::empty() is not const, it's not possible to use it during static initialization.

Is there another way to accomplish this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant