Open pseusys opened 2 weeks ago
Maybe I'm just not proficient with rust enough yet tho :(
Hi @pseusys, have you tried .clone()
? I'm pretty sure that should be implemented on all data structures.
Yes. I doublechecked that: it is implemented, but only in the latest releases (0.7.0), that are still release candidates. In the latest stable release, there is no Clone trait available.
I see your problem after digging into this a little bit deeper. Here's what I would suggest as a workaround. It's not ergonomic, but I think it should work:
if let NlPayload::Payload(recv_payload) = header.nl_payload {
if recv_payload.rtm_table == table_const {
let rm_msg = Nlmsghdr::new(None, Rtm::Delroute, NlmFFlags::new(&[NlmF::Request]), None, None, /* Reconstruct an NlPayload::(Rtmsg::new()) here. All of the fields are able to be copied and are public except for the attributes which can be borrowed. That should be sufficient for sending the message. /*);
sender_socket.send(rm_msg).unwrap();
table_data.push(recv_payload); // The above will not consume the data structure, just borrow it, so then you can move ownership to the vector.
}
}
Let me know if you need any more help with this.
I will come back to it again once 0.7.0 is released and try different solutions.
I would like to implement something close to
ip route save
command, store all the contents of a routing table and clear it.For that purpose I have implemented a simple function:
For now I am struggling with copying received
Rtmsg
instances. Basically I can not store them in an array and also use for removing from the table call at the same time, since they do not implementCopy
trait. How could I possibly save the message instance for future use and also remove it from the table? Is there a way to copy it?