Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Dretch opened this issue Jul 19, 2012 · 2 comments
Closed

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

Dretch opened this issue Jul 19, 2012 · 2 comments

Comments

@Dretch
Copy link
Contributor

Dretch commented Jul 19, 2012

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.

@catamorphism
Copy link
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!

@catamorphism
Copy link
Contributor

Closing this, but please do submit that pull request.

celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Dependency upgrade resulting from `cargo update`.

Co-authored-by: tautschnig <tautschnig@users.noreply.github.com>
Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants