-
Notifications
You must be signed in to change notification settings - Fork 159
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
Added examples for anonymous() and file() #45
Conversation
CI is failing because of |
Yah I agree. It should be possible to run only the non-doc tests using |
Thanks @omh1280 ! |
No problem :) I'll work on the rest of the public functions now |
Fixes #34 Just rebased (hope that's ok) and squashed all of the commits into one. Added a bunch of examples. Honestly, it became really hard to be creative in every example, but there is now a framework for people to add creativity to the examples :) How's it look? P.S. The tests will fail on CI because of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I just fixed up the CI scripts so that examples won't be compiled with rustc
1.8.0. If you can rebase over them, the build should go green.
src/lib.rs
Outdated
@@ -1,5 +1,5 @@ | |||
//! A cross-platform Rust API for memory maps. | |||
|
|||
//! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious - does this change the rendered output at all?
src/lib.rs
Outdated
/// | ||
/// // This is NOT allowed and will return an error, | ||
/// // since we are trying to make a `MmapMut` read-only. | ||
/// mmap.set_protection(Protection::Read)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should use unwrap_err
instead of ?
just to make it doubly-clear that it's supposed to fail? That would also allow the main()
method to use unwrap
, so that it's more tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, quick question: what is an allowable set_protection
? Because apparently going from ReadCopy
to ReadWrite
gives an error:
code: 87, message: "The parameter is incorrect"
But I can't put in a ReadWrite
to ReadCopy
example because it doesn't have permissions to open README.md
. (Unless the doc test is no_run
, but that defeats the purpose)
Also, as far as I can tell, there is no test for set_protection
, so I don't have anything to work off of (and I don't really understand why a user would change the protection of a mutable mmap).
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to go from Read
to ReadWrite
using set_protection
, but it requires the file to originally be opened with read
+ write
permissions (e.g. OpenOptions::new().read(true).write(true).open("foo.txt")
).
But I can't put in a ReadWrite to ReadCopy example because it doesn't have permissions to open README.md. (Unless the doc test is no_run, but that defeats the purpose)
Yah, it's not possible to remap from a SHARED mmap to a PRIVATE mmap, that's one of the reasons I think we're going to remove the protections system in favor of specific methods (see my recent comment on #33).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh cool, I forgot about OpenOptions.
Unfortunately, the map_mut
function denies Read
protection with "Invalid protection for a mutable mapping."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, again this is a great reason why Protection
should be removed. I'm going to work on that. I'd suggest skipping set_protection
in this example for now, or instead making the example use make_read_only
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #46 for what the API might look like. I'm going to merge yours first since that PR will take a while to land, so don't worry about potentia conflicts.
src/lib.rs
Outdated
/// use std::io::Write; | ||
/// use memmap::Protection; | ||
/// | ||
/// # fn try_main() -> Result<(), Box<Error>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to have these examples return io::Result<T>
instead of Result<T, Box<Error>>
. I think having the concrete return type of the methods is more instructive, especially when it's a common type like io::Error
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point
Watch out: some examples are `no_run` because they show writing to files.
Thanks again! |
For #34
Added examples for
anonymous()
andfile()
.Please let me know if these look OK! I'll write examples for the other functions if so.
I added
?
to all of the examples according to the API guidelines.Ottavio