Skip to content

Feature Request: Allow Custom Types for All Allocating Owned Types #156

@nu11ptr

Description

@nu11ptr

How It Works

  • Define or create required trait or traits for every major allocating type category (Box, Vec, String, Bytes, etc.)
    • These would need to handle creation, mutation and usage (within Buffa)
  • Implement only stdlib types (String, Vec, Box) and/or common 3rd party types (Bytes, etc.) in Buffa itself
  • Default to these implementations, but allow override via build.rs via API or buf via string options

Why?

  • Creates a universal mechanism for crate authors to implement Buffa support without Buffa authors constantly having to implement new feature requests for new types
  • Removes need for Buffa to be aware of these types at all, as well as need to stay up to date on their interface versioning
  • Applies to all allocated types, not just strings, since a user's allocation stress points and security needs are going to vary
  • Allows users to create their own wrapper types for types where crate authors choose not to implement Buffa support
  • Allows users to control things like allocation and security (Zeroize on Drop) based on their needs without involving Buffa authors
  • Increases Buffa's theoretical top end performance by optionally removing many allocations from encode/decode path

Examples:

  • FlexStr (String replacement) - not only supports ref counted and inline strings, but also zeroize on drop for security
    • Disclaimer: I am the author and maintainer of this crate
  • SmallBox (Box replacement) - supports inline boxed values up to a certain size then falls back to heap
  • SmallVec (Vec Replacement) - supports inline vec values up to a certain size then falls back to heap
  • SmallBytes (Bytes replacement) - wrapper over Smallvec for Bytes-like support

Challenges:

  • Naming the type - some of these types take multiple generic parameters, but only one of those needs dynamic replacement when used in a struct
    • Option: user supplies a type as a string with optional wildcard and Buffa parses the string into a full type: e.g. smallbox::SmallBox<*, S4> (where the * is replaced by whatever type you need in the box)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions