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

Added examples for anonymous() and file() #45

Merged
merged 1 commit into from May 30, 2017

Conversation

Projects
None yet
3 participants
@omh1280
Copy link
Contributor

omh1280 commented May 24, 2017

For #34
Added examples for anonymous() and file().

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

@omh1280 omh1280 changed the title Added examples for anonymous() and file(), and used ? operator in oth… Added examples for anonymous() and file() May 24, 2017

@omh1280

This comment has been minimized.

Copy link
Contributor Author

omh1280 commented May 24, 2017

CI is failing because of ?, but I think it's important to include in the example docs.

@danburkert

This comment has been minimized.

Copy link
Owner

danburkert commented May 24, 2017

I think it's important to include in the example docs.

Yah I agree. It should be possible to run only the non-doc tests using cargo test --lib, but it may require some surgery to ci/script.sh to figure out the rustc version and do a special test.

@brson

This comment has been minimized.

Copy link

brson commented May 24, 2017

Thanks @omh1280 !

@omh1280

This comment has been minimized.

Copy link
Contributor Author

omh1280 commented May 24, 2017

No problem :) I'll work on the rest of the public functions now

@omh1280 omh1280 force-pushed the omh1280:docs branch from d93fc14 to 2978d8e May 25, 2017

@omh1280

This comment has been minimized.

Copy link
Contributor Author

omh1280 commented May 25, 2017

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 ?, but they all pass on my machine.

@omh1280 omh1280 referenced this pull request May 25, 2017

Closed

Add examples to methods #34

@danburkert
Copy link
Owner

danburkert left a comment

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.

//!

This comment has been minimized.

@danburkert

danburkert May 29, 2017

Owner

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)?;

This comment has been minimized.

@danburkert

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.

@omh1280

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.

@danburkert

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.

@omh1280

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.

@danburkert

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.

@danburkert

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.

src/lib.rs Outdated
/// use std::io::Write;
/// use memmap::Protection;
///
/// # fn try_main() -> Result<(), Box<Error>> {

This comment has been minimized.

@danburkert

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.

@omh1280

omh1280 May 29, 2017

Author Contributor

Great point

@omh1280 omh1280 force-pushed the omh1280:docs branch from dfe6e2b to cf6f18e May 30, 2017

Added examples to methods.
Watch out: some examples are `no_run` because they show writing to files.

@omh1280 omh1280 force-pushed the omh1280:docs branch from cf6f18e to 322e94e May 30, 2017

@danburkert danburkert merged commit 5ff8bc3 into danburkert:master May 30, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@danburkert

This comment has been minimized.

Copy link
Owner

danburkert commented May 30, 2017

Thanks again!

@omh1280 omh1280 deleted the omh1280:docs branch May 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.