Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created April 30, 2024 12:57
Show Gist options
  • Save mizchi/d3ab781110814b6b46152c64ec4ad8b8 to your computer and use it in GitHub Desktop.
Save mizchi/d3ab781110814b6b46152c64ec4ad8b8 to your computer and use it in GitHub Desktop.
trait Serializer {
serialize(Self) -> Bytes
}
impl Serializer for Int with serialize(self) {
Bytes::from_array([
self.land(0xFF),
self.lsr(8).land(0xFF),
self.lsr(16).land(0xFF),
self.lsr(24).land(0xFF)
])
}
fn main {
let bytes = (1 as Serializer).serialize()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment