#T.to_bytes() without cloning the data?

32 messages · Page 1 of 1 (latest)

untold shadow
#

i want to be able to convert a type to bytes and back but do it without cloning the data,what functions provide this?

cosmic turret
#

Not all types can be converted to bytes so you're gonna have to be more specific.

untold shadow
#

so any type that can

#

like how would i convert i32 to a slice of bytes

cosmic turret
#

Any of the to_*_bytes functions.

honest dune
#

what endianness do you want the bytes to be?

#

why are you doing this in the first place?

untold shadow
honest dune
#

then it's not a slice

#

to_*_bytes functions return arrays

untold shadow
#

i didnt mean specifically those functions

#

just the function that can do that

honest dune
#

no function can do that

#

what are you doing?

untold shadow
#

writing a db

cosmic turret
#

So... You want serialization?

untold shadow
#

idk what that means

#

anyways even if it includes unsafe is there no way to turn a type to raw bytes without cloning it?

cosmic turret
#

What's wrong with the to_*_bytes functions

honest dune
#

?crate bytemuck

topaz owlBOT
#

A crate for mucking around with piles of bytes.

Version

1.14.0

Downloads

30 110 445

honest dune
#

?crate rkyv

topaz owlBOT
#

Zero-copy deserialization framework for Rust

Version

0.7.42

Downloads

9 164 911

untold shadow
#

which one would you say is better?

cosmic turret
#

They are for different uses

untold shadow
#

thanks

honest dune
#

they're mostly for inspiration

#

if you investigate fully what they offer then you will know a lot more how you want to approach your program

#

but you might want to use them directly

untold shadow
#

so youre saying i should make my own implementation of them?

honest dune
#

not necessarily, but if you're gonna be writing a db engine you will probably eventually write your own serialization traits