Skip to content

Customizable lenInternal? #9

Description

@elcritch

Thanks for the library! What do you think about making lenInternal customizable to different int types? Alternatively the smallest lenInternal size could be figured out at compile time.

I've been using it more lately for UI and CSS libraries only need ~60 letters for strings. That means Natural is as large as the text itself on a 64bit platform. :/

One way to do it automatically might be like:

type StackString*[Size: static Natural] = object
  ## A stack-allocated string with a fixed capacity
  when Size <= uint8.high():
    lenInternal: uint8
  elif Size <= uint16.high():
    lenInternal: uint16
  elif Size <= uint32.high():
    lenInternal: uint32
  elif Size <= uint64.high():
    lenInternal: uint64
  else:
    {.error: "size is too large to be stored: " & $Size.}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions