doc/wg/network/notes/network-notes-2023-12-14.md
dyn traits. But when we pass around static trait objects, we lose access to the underlying type and there's no way to reconstruct it.any trait in Rust can get the TypeID for a trait, which can let us convert a reference for a unknown type back into a proper type if those IDs match. That has a guarantee that things will actually match.dyn trait object from that reference. To convert back from the trait object to the original type, I tried to use the typecasting infrastructure by getting the type ID and doing a comparison for specific reference types. If they are equal, we can transmute, right? That was my first attempt in safe_upcast().Any object, which overloads the .type_id() field to reflect the proper underlying type.Any, then we can convert from trait object into an Any trait object. Then we can use the downcast_ref method to convert back into a struct.downcast_ref() panics?static types. So we can't use lifetimes everywhere and all buffers have to be static. This would be a bummer, but it's the Tock reality anyways.downcast_mut to get the original type. Or if it's wrong it panics right now.shrink_packet_buffer_headroom() checks that the parameters for the buffer are valid such that it could shrink in size. Then it does an unsafe transmute. While that does make sense conceptually, technically we're still converting between different types. So it's important for us to be sure that we can do this conversion without breaking any Rust invariants. One issue: Rust could choose different layouts or methods based on the generic parameters. We can prevent that by making a wrapper around our type. These parameters are markers, which shouldn't affect layout. So we should be able to have the PacketBuffer wrap a type which isn't generic over the parameters. So the method can pull out of one wrapper and put into another wrapper.downcast_mut anyways?