Skip to content

Generalize BitLength to work for non-usize types #347

Closed

Description

@briansmith

Example before:

        let mut completed_data_bits: u64 =
            self.completed_data_blocks
                .checked_mul(widen_u64(self.algorithm.block_len)).unwrap()
                .checked_add(widen_u64(self.num_pending)).unwrap()
                .checked_mul(8).unwrap();

Example after:

        let mut completed_data_bits: =
            BitLength::try_from_integer_bytes(self.completed_data_blocks
                .checked_mul(widen_u64(self.algorithm.block_len)).unwrap()
                .checked_add(widen_u64(self.num_pending)).unwrap())).unwrap();

(Whether we should be using unwrap() here is a separate issue.)

One problem is that we only want to support unsigned types in try_from_integer_bytes() but there's no standard trait for unsigned integer types, IIUC. num::traits might have something we can use.

Activity

  1. briansmith commented on Mar 25, 2019

    @briansmith
    OwnerAuthor

    Closing this as a dup of #350.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions