I can't allocate a new vector because of the performance reasons. I tried to iterate over the slice and send one by one, but it was too slow. How can I come up with a high performance solution to send it over a channel?
If you know how many slices maximum might be in-flight and their maximum capacity, you could pre-allocate a bunch of Vecs via with_capacity() and set up two channels: One to send the results and another to send the empties back for re-use.
I think you're saying that the Cow is in the Borrowed state, that it must be converted to the Owned state before it can be sent over the channel, and you don't want to convert it to the Owned state because of the allocation overhead. Is that right?
If so, my only thought is: If you convert it to the owned state in an Arc<...> (or Arc<Mutex<...>>), there will be allocation overhead, but at least the data can be shared between the sender and receiver.
It would really help if you could tell us more about the usage scenario.
I have a pre allocated vector in my struct and this struct receive data from UDPSocket. This receiver returns raw bytes Cow::from(&self.buffer[HEADER_SIZE_BYTES..size]) where buffer is a Vec. After that this Cow is used in the parser and parser also has a preallocated vector. Parser converts bytes into Data Structs, depending on the first bytes. At the end of the parser, it returns Cow::from(&self.parsed) where parsed is a Vec.
After those, I need to push the parsed Data Structs into the channel, so this thread can receive messages without any delay and missing any packet.