Skip to content

write_to_prefix (and similar ones) take ownership of the buffer #195

@SuperKenVery

Description

@SuperKenVery

Please correct me if I'm wrong, but by taking ownership of the buffer, it seems to release the buffer as soon as the function exits, and subsequent code cannot use the buffer.

The method is defined as follows:

    /// Writes a copy of `self` to the prefix of `bytes`.
    ///
    /// `write_to_prefix` writes `self` to the first `size_of_val(self)` bytes
    /// of `bytes`. If `bytes.len() < size_of_val(self)`, it returns `None`.
    fn write_to_prefix<B: ByteSliceMut>(&self, mut bytes: B) -> Option<()> {
        let size = mem::size_of_val(self);
        if bytes.len() < size {
            return None;
        }

        bytes[..size].copy_from_slice(self.as_bytes());
        Some(())
    }

I think the method should only borrow the buffer.

Again, correct me if I'm wrong please!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions