Skip to content

Store bytes in memory rather than hex string #1365

@chaoticlonghair

Description

@chaoticlonghair

Contact Details

No response

Propose-a-new-feature

Store bytes in memory rather than hex string.

pub struct Hex(String);

PROS:

  • Half memory cost.

  • No error handling.

    Converting hex string to bytes require error handling; conversely, are not.

    pub fn as_bytes(&self) -> Bytes {
    Bytes::from(hex_decode(&self.0[2..]).expect("impossible, already checked in from_string"))
    }

  • Slice has a higher usage rate.

  • If using bytes::Bytes as inner type (rather than Vec<u8>):

    • Cloning bytes::Bytes is very cheap.

Alternatives you've considered

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions