-
Notifications
You must be signed in to change notification settings - Fork 133
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
feature request: integrating with the os_units
crate
#288
Comments
I don't think we would really need the However, having a EDIT: If the arithmetic ops are the only reason to have a |
I think this is a great improvement. Actually, I couldn't find any methods that can use the |
I would want to get @phil-opp's input from a design perspective. If we added methods like let page1 = Page::containing_address(...);
let page2 = Page::containing_address(...);
let diff: u64 = page2 - page1; // Page<S>: Sub<Self> (would be replaced by pages_between)
let next_page = page1 + 1; // Page<S>: Add<u64>
let prev_page = page2 - 1; // Page<S>: Sub<u64> or none of it. All three implementations run the risk of ambiguity between a number of bytes and a number of pages. |
Some early thoughts: I agree that I'm not sure if I like the naming of Also, if we go with |
I agree with @phil-opp's comments above. Personally I don't find the existing implementations that confusing. Especially if we add a |
I'd like to suggest integrating my
os_units
crate into thex86_64
crate.Descriptions
The
os_units
crate provides two types:Bytes
andNumOfPages
. These types are interactive because of two methods:Bytes::as_num_of_pages
andNumOfPages::as_bytes
. Note thatBytes::as_num_of_pages
returns the number of pages that is more than the bytes the instance ofBytes
contains.Advantages
Some methods will have more explicit return types. For example,
Page
implementsSub<Self>
. However, the return type isu64
, and it doesn't provide the information whether the number represents the bytes of pages or the number of pages (at first, I thought it was former). The users can read the docs (by the way, there is no information of its return type except the source code), but returningNumOfPages
will prevent bugs because of the mismatch of types.Drawbacks
The users will have to call
as_usize
(oras_u64
to match with the address types) each time, increasing the size of the code.Notes
These two types use
usize
, notu64
. However, changing the type tou64
will be better because this crate mainly uses it.The text was updated successfully, but these errors were encountered: