Skip to content

Define CheckedAdd and CheckedSub traits #293

Description

@ncatelli

There are a few places where I've seen, or they could benefit from a, checked_add and checked_sub implementations throughout the library, such as on VirtAddr, PhysFrame, PhysAddr... etc. I would like to define a CheckedAdd and CheckedSub trait similar to the std::ops::Add trait that defines a checked_* method.

pub trait CheckedAdd<Rhs = Self> {
    type Output;

    fn checked_add(self, rhs: Rhs) -> Option<Self::Output>;
}
pub trait CheckedSub<Rhs = Self> {
    type Output;

    fn checked_sub(self, rhs: Rhs) -> Option<Self::Output>;
}

I would like to add this specifically to provide for checked_operations across multiple Rhs types. An example being a CheckedAdd<Rhs=PhysFrame> for PhysFrame and CheckedAdd<Rhs=PhysAddr> for PhysFrame.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions