1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: Apache-2.0
//! The `mmarinus` crate wraps the underlying system `mmap()` call in safe semantics.
//!
//! For example:
//!
//! ```rust
//! use mmarinus::{Map, perms};
//!
//! let mut zero = std::fs::File::open("/dev/zero").unwrap();
//!
//! let map = Map::bytes(32)
//! .near(128 * 1024 * 1024)
//! .from(&mut zero, 0)
//! .with(perms::Read)
//! .unwrap();
//!
//! assert_eq!(&*map, &[0; 32]);
//! ```
//!
//! You can also remap an existing mapping:
//!
//! ```rust
//! use mmarinus::{Map, perms};
//!
//! let mut zero = std::fs::File::open("/dev/zero").unwrap();
//!
//! let mut map = Map::bytes(32)
//! .anywhere()
//! .from(&mut zero, 0)
//! .with(perms::Read)
//! .unwrap();
//!
//! assert_eq!(&*map, &[0; 32]);
//!
//! let mut map = map.remap()
//! .from(&mut zero, 0)
//! .with(perms::ReadWrite)
//! .unwrap();
//!
//! assert_eq!(&*map, &[0; 32]);
//! for i in map.iter_mut() {
//! *i = 255;
//! }
//! assert_eq!(&*map, &[255; 32]);
//! ```
//!
//! Alternatively, you can just change the permissions:
//!
//! ```rust
//! use mmarinus::{Map, perms};
//!
//! let mut zero = std::fs::File::open("/dev/zero").unwrap();
//!
//! let mut map = Map::bytes(32)
//! .at(128 * 1024 * 1024)
//! .from(&mut zero, 0)
//! .with(perms::Read)
//! .unwrap();
//!
//! assert_eq!(&*map, &[0; 32]);
//!
//! let mut map = map.reprotect(perms::ReadWrite).unwrap();
//!
//! assert_eq!(&*map, &[0; 32]);
//! for i in map.iter_mut() {
//! *i = 255;
//! }
//! assert_eq!(&*map, &[255; 32]);
//! ```
//!
//! Mapping a whole file into memory is easy:
//!
//! ```rust
//! use mmarinus::{Map, Private, perms};
//!
//! let map = Map::load("/etc/os-release", Private, perms::Read).unwrap();
//! ```
pub use Error;
pub use ;