chaokunyang opened a new issue, #2552:
URL: https://github.com/apache/fory/issues/2552
### Feature Request
Currently fory rust provide following deserialize API:
```rust
pub fn deserialize<T: Serializer>(&self, bf: &[u8]) -> Result<T, Error> {
let mut reader = Reader::new(bf);
let meta_offset = self.read_head(&mut reader)?;
let mut context = ReadContext::new(self, reader);
if meta_offset > 0 {
context.load_meta(meta_offset as usize);
}
<T as Serializer>::deserialize(&mut context)
}
```
It relies on compiler `Return Value Optimization (RVO)`, which won't work
always. And the compiler will copy small struct always.
### Is your feature request related to a problem? Please describe
` pub fn deserialize<T: Serializer>(&self, bf: &[u8]) -> Result<T, Error>`
API may introduce extra copy.
### Describe the solution you'd like
Add a new API to populate passed struct directly.
```rust
pub fn deserialize_into<T: Serializer>(&self, bf: &[u8], output: &mut T) ->
Result<(), Error> {
let mut reader = Reader::new(bf);
let meta_offset = self.read_head(&mut reader)?;
let mut context = ReadContext::new(self, reader);
if meta_offset > 0 {
context.load_meta(meta_offset as usize);
}
<T as Serializer>::deserialize_into(&mut context, output)
}
```
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]