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

Introduce FixedPoint::into_bits #12

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::fmt::{Display, Formatter, Result};
use derive_more::Error;

#[cfg_attr(feature = "std", derive(Error))]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Copy instance prevents us from adding a non-trivial object inside (i.e stacktraces).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment this error doesn't contain it.
Once you decide to add, you can remove Copy (adding a new variant is also considered to be a breaking change).

pub enum ArithmeticError {
Overflow,
DivisionByZero,
Expand All @@ -26,7 +26,7 @@ impl Display for ArithmeticError {
}

#[cfg_attr(feature = "std", derive(Error))]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FromDecimalError {
UnsupportedExponent,
TooBigMantissa,
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ impl<I, P> FixedPoint<I, P> {
pub const fn as_bits(&self) -> &I {
&self.inner
}

#[inline]
pub fn into_bits(self) -> I {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think it can be const fn.
  2. Add #[inline] in order to enable inlining across crates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It consumes self. The compiler said no.
  2. Sure.

self.inner
}
}

macro_rules! impl_fixed_point {
Expand Down