Open Fomys opened 2 years ago
Can you talk more about what this is useful for? Why do you want to avoid making a slice? I'm somewhat wary of adding unsafe
APIs like this unless they pull their weight.
My specific case is to create a common interface for a protocol over can bus between a raspberry-pi and multiple stm32 (which use canfd and bxcan). I don't want to create multiple function to parse and create specific packet for each interface, it will be redundant and error prone if I have to do that three times, especially because my protocol may change with time.
So I created a function which transform my protocol into a tuple (size: u8, data: [u8;8]). Actually, in the bxcan implementation I have to transform my tuple to a slice before creating the Data struct. As the Data struct contains already only those informations. I think the overhead brought by the slice and the copy is not necessary and can be avoided. I'm open to other solution, but I think it's a good way to do that.
This addition allows the creation of Data without using slices. It's useful when you already have the len and the [u8; 8].