Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded examples for anonymous() and file() #45
Conversation
omh1280
changed the title
Added examples for anonymous() and file(), and used ? operator in oth…
Added examples for anonymous() and file()
May 24, 2017
This comment has been minimized.
This comment has been minimized.
|
CI is failing because of |
This comment has been minimized.
This comment has been minimized.
Yah I agree. It should be possible to run only the non-doc tests using |
This comment has been minimized.
This comment has been minimized.
brson
commented
May 24, 2017
|
Thanks @omh1280 ! |
This comment has been minimized.
This comment has been minimized.
|
No problem :) I'll work on the rest of the public functions now |
omh1280
force-pushed the
omh1280:docs
branch
from
d93fc14
to
2978d8e
May 25, 2017
This comment has been minimized.
This comment has been minimized.
|
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 |
danburkert
requested changes
May 29, 2017
|
Thanks! I just fixed up the CI scripts so that examples won't be compiled with |
| @@ -1,5 +1,5 @@ | |||
| //! A cross-platform Rust API for memory maps. | |||
|
|
|||
| //! | |||
This comment has been minimized.
This comment has been minimized.
| /// | ||
| /// // This is NOT allowed and will return an error, | ||
| /// // since we are trying to make a `MmapMut` read-only. | ||
| /// mmap.set_protection(Protection::Read)?; |
This comment has been minimized.
This comment has been minimized.
danburkert
May 29, 2017
Owner
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.
This comment has been minimized.
This comment has been minimized.
omh1280
May 29, 2017
Author
Contributor
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!
This comment has been minimized.
This comment has been minimized.
danburkert
May 29, 2017
Owner
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).
This comment has been minimized.
This comment has been minimized.
omh1280
May 30, 2017
Author
Contributor
Oh cool, I forgot about OpenOptions.
Unfortunately, the map_mut function denies Read protection with "Invalid protection for a mutable mapping."
This comment has been minimized.
This comment has been minimized.
danburkert
May 30, 2017
Owner
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.
This comment has been minimized.
This comment has been minimized.
danburkert
May 30, 2017
Owner
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.
| /// use std::io::Write; | ||
| /// use memmap::Protection; | ||
| /// | ||
| /// # fn try_main() -> Result<(), Box<Error>> { |
This comment has been minimized.
This comment has been minimized.
danburkert
May 29, 2017
Owner
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.
This comment has been minimized.
This comment has been minimized.
omh1280
force-pushed the
omh1280:docs
branch
from
dfe6e2b
to
cf6f18e
May 30, 2017
omh1280
force-pushed the
omh1280:docs
branch
from
cf6f18e
to
322e94e
May 30, 2017
danburkert
merged commit 5ff8bc3
into
danburkert:master
May 30, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks again! |
omh1280 commentedMay 24, 2017
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