Serializes a value of type `T` into a byte vector. # Type Parameters `T` - The type of the value to serialize. Must implement `Serializer`. # Arguments `record` - A reference to the value to serialize. # Returns A `Vec ` containing the serialized data. # Examples ```rust, ignore use fory::Fory; use fory::{ForyEnum, ForyStruct, ForyUnion}; #[derive(ForyStruct)] struct Point { x: i32, y:
(&self, record: &T)
| 554 | /// let bytes = fory.serialize(&point).unwrap(); |
| 555 | /// ``` |
| 556 | pub fn serialize<T: Serializer>(&self, record: &T) -> Result<Vec<u8>, Error> { |
| 557 | self.with_write_context( |
| 558 | |context| match self.serialize_with_context(record, context) { |
| 559 | Ok(_) => { |
| 560 | let result = context.writer.dump(); |
| 561 | context.writer.reset(); |
| 562 | Ok(result) |
| 563 | } |
| 564 | Err(err) => { |
| 565 | context.writer.reset(); |
| 566 | Err(err) |
| 567 | } |
| 568 | }, |
| 569 | ) |
| 570 | } |
| 571 | |
| 572 | /// Serializes a value of type `T` into the provided byte buffer. |
| 573 | /// |