Skip to content

Additional constructors/possible-classification for std::bitv #2964

Closed

Description

@Dretch

I have written these functions for my own use, but I would like it better if they were inside std::bitv:

/**
 * Transform a byte-vector into a bitv. Each byte becomes 8 bits,
 * with the most significant bits of each byte coming first. Each
 * bit becomes true if equal to 1 or false if equal to 0.
 */
fn from_bytes(bytes: [u8]) -> bitv;

/**
 * Transform a [bool] into a bitv by converting each bool into a bit.
 */
fn from_bools(bools: [bool]) -> bitv;

/**
 * Create a bitv of the specified length where the value at each
 * index is f(index).
 */
fn from_fn(len: uint, f: fn(index: uint) -> bool) -> bitv;

(there are also corresponding to_bytes/to_bools methods).

As a separate but related issue, I think it would be nice if the bitv type was turned into a class and its internal data marked as private members.

As either of these requests pleasing to you? I can provide pull requests (with tests/docs/etc) if they are.

Activity

  1. catamorphism commented on Jul 19, 2012

    @catamorphism
    Contributor

    There's already a bug for the second issue: #2341 - I actually have a patch for this, but it's not working and I haven't gotten around to figuring out why.

    Feel free to submit a pull request for the added functions! Thanks!

  2. catamorphism commented on Jul 20, 2012

    @catamorphism
    Contributor

    Closing this, but please do submit that pull request.

  3. added a commit that references this issue on Aug 19, 2026
  4. added a commit that references this issue on Aug 21, 2026
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions