prometheus-client-mmap 1.2.4-x86_64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.tool-versions +1 -0
- data/README.md +281 -0
- data/ext/fast_mmaped_file_rs/Cargo.toml +35 -0
- data/ext/fast_mmaped_file_rs/README.md +52 -0
- data/ext/fast_mmaped_file_rs/build.rs +5 -0
- data/ext/fast_mmaped_file_rs/extconf.rb +28 -0
- data/ext/fast_mmaped_file_rs/src/error.rs +174 -0
- data/ext/fast_mmaped_file_rs/src/file_entry.rs +784 -0
- data/ext/fast_mmaped_file_rs/src/file_info.rs +240 -0
- data/ext/fast_mmaped_file_rs/src/lib.rs +78 -0
- data/ext/fast_mmaped_file_rs/src/macros.rs +14 -0
- data/ext/fast_mmaped_file_rs/src/map.rs +492 -0
- data/ext/fast_mmaped_file_rs/src/mmap/inner.rs +704 -0
- data/ext/fast_mmaped_file_rs/src/mmap.rs +891 -0
- data/ext/fast_mmaped_file_rs/src/raw_entry.rs +473 -0
- data/ext/fast_mmaped_file_rs/src/testhelper.rs +222 -0
- data/ext/fast_mmaped_file_rs/src/util.rs +121 -0
- data/lib/3.1/fast_mmaped_file_rs.so +0 -0
- data/lib/3.2/fast_mmaped_file_rs.so +0 -0
- data/lib/3.3/fast_mmaped_file_rs.so +0 -0
- data/lib/3.4/fast_mmaped_file_rs.so +0 -0
- data/lib/prometheus/client/configuration.rb +23 -0
- data/lib/prometheus/client/counter.rb +27 -0
- data/lib/prometheus/client/formats/text.rb +85 -0
- data/lib/prometheus/client/gauge.rb +40 -0
- data/lib/prometheus/client/helper/entry_parser.rb +132 -0
- data/lib/prometheus/client/helper/file_locker.rb +50 -0
- data/lib/prometheus/client/helper/json_parser.rb +23 -0
- data/lib/prometheus/client/helper/metrics_processing.rb +45 -0
- data/lib/prometheus/client/helper/metrics_representation.rb +51 -0
- data/lib/prometheus/client/helper/mmaped_file.rb +64 -0
- data/lib/prometheus/client/helper/plain_file.rb +29 -0
- data/lib/prometheus/client/histogram.rb +80 -0
- data/lib/prometheus/client/label_set_validator.rb +85 -0
- data/lib/prometheus/client/metric.rb +80 -0
- data/lib/prometheus/client/mmaped_dict.rb +79 -0
- data/lib/prometheus/client/mmaped_value.rb +154 -0
- data/lib/prometheus/client/page_size.rb +17 -0
- data/lib/prometheus/client/push.rb +203 -0
- data/lib/prometheus/client/rack/collector.rb +88 -0
- data/lib/prometheus/client/rack/exporter.rb +96 -0
- data/lib/prometheus/client/registry.rb +65 -0
- data/lib/prometheus/client/simple_value.rb +31 -0
- data/lib/prometheus/client/summary.rb +69 -0
- data/lib/prometheus/client/support/puma.rb +44 -0
- data/lib/prometheus/client/support/unicorn.rb +35 -0
- data/lib/prometheus/client/uses_value_type.rb +20 -0
- data/lib/prometheus/client/version.rb +5 -0
- data/lib/prometheus/client.rb +58 -0
- data/lib/prometheus.rb +3 -0
- metadata +249 -0
| @@ -0,0 +1,240 @@ | |
| 1 | 
            +
            use magnus::exception::*;
         | 
| 2 | 
            +
            use magnus::{Error, RString, Symbol, Value};
         | 
| 3 | 
            +
            use std::ffi::OsString;
         | 
| 4 | 
            +
            use std::fs::File;
         | 
| 5 | 
            +
            use std::io::{self, Read, Seek};
         | 
| 6 | 
            +
            use std::os::unix::ffi::OsStringExt;
         | 
| 7 | 
            +
            use std::path::PathBuf;
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            use crate::err;
         | 
| 10 | 
            +
            use crate::error::{MmapError, RubyError};
         | 
| 11 | 
            +
            use crate::util;
         | 
| 12 | 
            +
            use crate::Result;
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            /// The details of a `*.db` file.
         | 
| 15 | 
            +
            #[derive(Debug)]
         | 
| 16 | 
            +
            pub struct FileInfo {
         | 
| 17 | 
            +
                pub file: File,
         | 
| 18 | 
            +
                pub path: PathBuf,
         | 
| 19 | 
            +
                pub len: usize,
         | 
| 20 | 
            +
                pub multiprocess_mode: Symbol,
         | 
| 21 | 
            +
                pub type_: Symbol,
         | 
| 22 | 
            +
                pub pid: String,
         | 
| 23 | 
            +
            }
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            impl FileInfo {
         | 
| 26 | 
            +
                /// Receive the details of a file from Ruby and store as a `FileInfo`.
         | 
| 27 | 
            +
                pub fn open_from_params(params: &[Value; 4]) -> magnus::error::Result<Self> {
         | 
| 28 | 
            +
                    if params.len() != 4 {
         | 
| 29 | 
            +
                        return Err(err!(
         | 
| 30 | 
            +
                            arg_error(),
         | 
| 31 | 
            +
                            "wrong number of arguments {} instead of 4",
         | 
| 32 | 
            +
                            params.len()
         | 
| 33 | 
            +
                        ));
         | 
| 34 | 
            +
                    }
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    let filepath = RString::from_value(params[0])
         | 
| 37 | 
            +
                        .ok_or_else(|| err!(arg_error(), "can't convert filepath to String"))?;
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    // SAFETY: We immediately copy the string buffer from Ruby, preventing
         | 
| 40 | 
            +
                    // it from being mutated out from under us.
         | 
| 41 | 
            +
                    let path_bytes: Vec<_> = unsafe { filepath.as_slice().to_owned() };
         | 
| 42 | 
            +
                    let path = PathBuf::from(OsString::from_vec(path_bytes));
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    let mut file = File::open(&path).map_err(|_| {
         | 
| 45 | 
            +
                        err!(
         | 
| 46 | 
            +
                            arg_error(),
         | 
| 47 | 
            +
                            "Can't open {}, errno: {}",
         | 
| 48 | 
            +
                            path.display(),
         | 
| 49 | 
            +
                            util::errno()
         | 
| 50 | 
            +
                        )
         | 
| 51 | 
            +
                    })?;
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    let stat = file
         | 
| 54 | 
            +
                        .metadata()
         | 
| 55 | 
            +
                        .map_err(|_| err!(io_error(), "Can't stat file, errno: {}", util::errno()))?;
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                    let length = util::cast_chk::<_, usize>(stat.len(), "file size")?;
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    let multiprocess_mode = Symbol::from_value(params[1])
         | 
| 60 | 
            +
                        .ok_or_else(|| err!(arg_error(), "expected multiprocess_mode to be a symbol"))?;
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    let type_ = Symbol::from_value(params[2])
         | 
| 63 | 
            +
                        .ok_or_else(|| err!(arg_error(), "expected file type to be a symbol"))?;
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                    let pid = RString::from_value(params[3])
         | 
| 66 | 
            +
                        .ok_or_else(|| err!(arg_error(), "expected pid to be a String"))?;
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    file.rewind()
         | 
| 69 | 
            +
                        .map_err(|_| err!(io_error(), "Can't fseek 0, errno: {}", util::errno()))?;
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    Ok(Self {
         | 
| 72 | 
            +
                        file,
         | 
| 73 | 
            +
                        path,
         | 
| 74 | 
            +
                        len: length,
         | 
| 75 | 
            +
                        multiprocess_mode,
         | 
| 76 | 
            +
                        type_,
         | 
| 77 | 
            +
                        pid: pid.to_string()?,
         | 
| 78 | 
            +
                    })
         | 
| 79 | 
            +
                }
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                /// Read the contents of the associated file into the buffer provided by
         | 
| 82 | 
            +
                /// the caller.
         | 
| 83 | 
            +
                pub fn read_from_file(&mut self, buf: &mut Vec<u8>) -> Result<()> {
         | 
| 84 | 
            +
                    buf.clear();
         | 
| 85 | 
            +
                    buf.try_reserve(self.len).map_err(|_| {
         | 
| 86 | 
            +
                        MmapError::legacy(
         | 
| 87 | 
            +
                            format!("Can't malloc {}, errno: {}", self.len, util::errno()),
         | 
| 88 | 
            +
                            RubyError::Io,
         | 
| 89 | 
            +
                        )
         | 
| 90 | 
            +
                    })?;
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                    match self.file.read_to_end(buf) {
         | 
| 93 | 
            +
                        Ok(n) if n == self.len => Ok(()),
         | 
| 94 | 
            +
                        // A worker may expand the file between our `stat` and `read`, no harm done.
         | 
| 95 | 
            +
                        Ok(n) if n > self.len => {
         | 
| 96 | 
            +
                            self.len = n;
         | 
| 97 | 
            +
                            Ok(())
         | 
| 98 | 
            +
                        }
         | 
| 99 | 
            +
                        Ok(_) => Err(MmapError::io(
         | 
| 100 | 
            +
                            "read",
         | 
| 101 | 
            +
                            &self.path,
         | 
| 102 | 
            +
                            io::Error::from(io::ErrorKind::UnexpectedEof),
         | 
| 103 | 
            +
                        )),
         | 
| 104 | 
            +
                        Err(e) => Err(MmapError::io("read", &self.path, e)),
         | 
| 105 | 
            +
                    }
         | 
| 106 | 
            +
                }
         | 
| 107 | 
            +
            }
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            #[cfg(test)]
         | 
| 110 | 
            +
            mod test {
         | 
| 111 | 
            +
                use magnus::{eval, RArray, Symbol};
         | 
| 112 | 
            +
                use rand::{thread_rng, Rng};
         | 
| 113 | 
            +
                use sha2::{Digest, Sha256};
         | 
| 114 | 
            +
                use std::fs;
         | 
| 115 | 
            +
                use std::io::Write;
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                use super::*;
         | 
| 118 | 
            +
                use crate::testhelper::TestFile;
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                #[test]
         | 
| 121 | 
            +
                fn test_open_from_params() {
         | 
| 122 | 
            +
                    let _cleanup = unsafe { magnus::embed::init() };
         | 
| 123 | 
            +
                    let ruby = magnus::Ruby::get().unwrap();
         | 
| 124 | 
            +
                    crate::init(&ruby).unwrap();
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                    let file_data = b"foobar";
         | 
| 127 | 
            +
                    let TestFile {
         | 
| 128 | 
            +
                        file: _file,
         | 
| 129 | 
            +
                        path,
         | 
| 130 | 
            +
                        dir: _dir,
         | 
| 131 | 
            +
                    } = TestFile::new(file_data);
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                    let pid = "worker-1_0";
         | 
| 134 | 
            +
                    let args = RArray::from_value(
         | 
| 135 | 
            +
                        eval(&format!("['{}', :max, :gauge, '{pid}']", path.display())).unwrap(),
         | 
| 136 | 
            +
                    )
         | 
| 137 | 
            +
                    .unwrap();
         | 
| 138 | 
            +
                    let arg0 = args.shift().unwrap();
         | 
| 139 | 
            +
                    let arg1 = args.shift().unwrap();
         | 
| 140 | 
            +
                    let arg2 = args.shift().unwrap();
         | 
| 141 | 
            +
                    let arg3 = args.shift().unwrap();
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                    let out = FileInfo::open_from_params(&[arg0, arg1, arg2, arg3]);
         | 
| 144 | 
            +
                    assert!(out.is_ok());
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                    let out = out.unwrap();
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                    assert_eq!(out.path, path);
         | 
| 149 | 
            +
                    assert_eq!(out.len, file_data.len());
         | 
| 150 | 
            +
                    assert_eq!(out.multiprocess_mode, Symbol::new("max"));
         | 
| 151 | 
            +
                    assert_eq!(out.type_, Symbol::new("gauge"));
         | 
| 152 | 
            +
                    assert_eq!(out.pid, pid);
         | 
| 153 | 
            +
                }
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                #[test]
         | 
| 156 | 
            +
                fn test_read_from_file() {
         | 
| 157 | 
            +
                    let _cleanup = unsafe { magnus::embed::init() };
         | 
| 158 | 
            +
                    let ruby = magnus::Ruby::get().unwrap();
         | 
| 159 | 
            +
                    crate::init(&ruby).unwrap();
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                    const BUF_LEN: usize = 1 << 20; // 1MiB
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                    // Create a buffer with random data.
         | 
| 164 | 
            +
                    let mut buf = vec![0u8; BUF_LEN];
         | 
| 165 | 
            +
                    thread_rng().fill(buf.as_mut_slice());
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                    let TestFile {
         | 
| 168 | 
            +
                        file,
         | 
| 169 | 
            +
                        path,
         | 
| 170 | 
            +
                        dir: _dir,
         | 
| 171 | 
            +
                    } = TestFile::new(&buf);
         | 
| 172 | 
            +
             | 
| 173 | 
            +
                    let mut info = FileInfo {
         | 
| 174 | 
            +
                        file,
         | 
| 175 | 
            +
                        path: path.clone(),
         | 
| 176 | 
            +
                        len: buf.len(),
         | 
| 177 | 
            +
                        multiprocess_mode: Symbol::new("puma"),
         | 
| 178 | 
            +
                        type_: Symbol::new("max"),
         | 
| 179 | 
            +
                        pid: "worker-0_0".to_string(),
         | 
| 180 | 
            +
                    };
         | 
| 181 | 
            +
             | 
| 182 | 
            +
                    let mut out_buf = Vec::new();
         | 
| 183 | 
            +
                    info.read_from_file(&mut out_buf).unwrap();
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                    assert_eq!(buf.len(), out_buf.len(), "buffer lens");
         | 
| 186 | 
            +
             | 
| 187 | 
            +
                    let mut in_hasher = Sha256::new();
         | 
| 188 | 
            +
                    in_hasher.update(&buf);
         | 
| 189 | 
            +
                    let in_hash = in_hasher.finalize();
         | 
| 190 | 
            +
             | 
| 191 | 
            +
                    let mut out_hasher = Sha256::new();
         | 
| 192 | 
            +
                    out_hasher.update(&out_buf);
         | 
| 193 | 
            +
                    let out_hash = out_hasher.finalize();
         | 
| 194 | 
            +
             | 
| 195 | 
            +
                    assert_eq!(in_hash, out_hash, "content hashes");
         | 
| 196 | 
            +
                }
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                #[test]
         | 
| 199 | 
            +
                fn test_read_from_file_resized() {
         | 
| 200 | 
            +
                    let _cleanup = unsafe { magnus::embed::init() };
         | 
| 201 | 
            +
                    let ruby = magnus::Ruby::get().unwrap();
         | 
| 202 | 
            +
                    crate::init(&ruby).unwrap();
         | 
| 203 | 
            +
             | 
| 204 | 
            +
                    const BUF_LEN: usize = 1 << 14; // 16KiB
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                    // Create a buffer with random data.
         | 
| 207 | 
            +
                    let mut buf = vec![0u8; BUF_LEN];
         | 
| 208 | 
            +
                    thread_rng().fill(buf.as_mut_slice());
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                    let TestFile {
         | 
| 211 | 
            +
                        file,
         | 
| 212 | 
            +
                        path,
         | 
| 213 | 
            +
                        dir: _dir,
         | 
| 214 | 
            +
                    } = TestFile::new(&buf);
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                    let mut info = FileInfo {
         | 
| 217 | 
            +
                        file,
         | 
| 218 | 
            +
                        path: path.clone(),
         | 
| 219 | 
            +
                        len: buf.len(),
         | 
| 220 | 
            +
                        multiprocess_mode: Symbol::new("puma"),
         | 
| 221 | 
            +
                        type_: Symbol::new("max"),
         | 
| 222 | 
            +
                        pid: "worker-0_0".to_string(),
         | 
| 223 | 
            +
                    };
         | 
| 224 | 
            +
             | 
| 225 | 
            +
                    let mut resized_file = fs::OpenOptions::new()
         | 
| 226 | 
            +
                        .write(true)
         | 
| 227 | 
            +
                        .append(true)
         | 
| 228 | 
            +
                        .open(path)
         | 
| 229 | 
            +
                        .unwrap();
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                    // Write data to file after it has been `stat`ed in the
         | 
| 232 | 
            +
                    // constructor.
         | 
| 233 | 
            +
                    resized_file.write_all(&[1; 1024]).unwrap();
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                    let mut out_buf = Vec::new();
         | 
| 236 | 
            +
                    info.read_from_file(&mut out_buf).unwrap();
         | 
| 237 | 
            +
             | 
| 238 | 
            +
                    assert_eq!(BUF_LEN + 1024, info.len, "resized file updated len");
         | 
| 239 | 
            +
                }
         | 
| 240 | 
            +
            }
         | 
| @@ -0,0 +1,78 @@ | |
| 1 | 
            +
            use magnus::exception::*;
         | 
| 2 | 
            +
            use magnus::prelude::*;
         | 
| 3 | 
            +
            use magnus::value::{Fixnum, Lazy, LazyId};
         | 
| 4 | 
            +
            use magnus::{class, define_class, exception, function, method, Ruby};
         | 
| 5 | 
            +
            use std::mem::size_of;
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            use crate::mmap::MmapedFile;
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            pub mod error;
         | 
| 10 | 
            +
            pub mod file_entry;
         | 
| 11 | 
            +
            pub mod file_info;
         | 
| 12 | 
            +
            mod macros;
         | 
| 13 | 
            +
            pub mod map;
         | 
| 14 | 
            +
            pub mod mmap;
         | 
| 15 | 
            +
            pub mod raw_entry;
         | 
| 16 | 
            +
            pub mod util;
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            #[cfg(test)]
         | 
| 19 | 
            +
            mod testhelper;
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            type Result<T> = std::result::Result<T, crate::error::MmapError>;
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            const MAP_SHARED: i64 = libc::MAP_SHARED as i64;
         | 
| 24 | 
            +
            const HEADER_SIZE: usize = 2 * size_of::<u32>();
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            static SYM_GAUGE: LazyId = LazyId::new("gauge");
         | 
| 27 | 
            +
            static SYM_MIN: LazyId = LazyId::new("min");
         | 
| 28 | 
            +
            static SYM_MAX: LazyId = LazyId::new("max");
         | 
| 29 | 
            +
            static SYM_LIVESUM: LazyId = LazyId::new("livesum");
         | 
| 30 | 
            +
            static SYM_PID: LazyId = LazyId::new("pid");
         | 
| 31 | 
            +
            static SYM_SAMPLES: LazyId = LazyId::new("samples");
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            static PROM_EPARSING_ERROR: Lazy<ExceptionClass> = Lazy::new(|_| {
         | 
| 34 | 
            +
                let prom_err = define_class(
         | 
| 35 | 
            +
                    "PrometheusParsingError",
         | 
| 36 | 
            +
                    exception::runtime_error().as_r_class(),
         | 
| 37 | 
            +
                )
         | 
| 38 | 
            +
                .expect("failed to create class `PrometheusParsingError`");
         | 
| 39 | 
            +
                ExceptionClass::from_value(prom_err.as_value())
         | 
| 40 | 
            +
                    .expect("failed to create exception class from `PrometheusParsingError`")
         | 
| 41 | 
            +
            });
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            #[magnus::init]
         | 
| 44 | 
            +
            fn init(ruby: &Ruby) -> magnus::error::Result<()> {
         | 
| 45 | 
            +
                // Initialize the static symbols
         | 
| 46 | 
            +
                LazyId::force(&SYM_GAUGE, ruby);
         | 
| 47 | 
            +
                LazyId::force(&SYM_MIN, ruby);
         | 
| 48 | 
            +
                LazyId::force(&SYM_MAX, ruby);
         | 
| 49 | 
            +
                LazyId::force(&SYM_LIVESUM, ruby);
         | 
| 50 | 
            +
                LazyId::force(&SYM_PID, ruby);
         | 
| 51 | 
            +
                LazyId::force(&SYM_SAMPLES, ruby);
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                // Initialize `PrometheusParsingError` class.
         | 
| 54 | 
            +
                Lazy::force(&PROM_EPARSING_ERROR, ruby);
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                let klass = define_class("FastMmapedFileRs", class::object())?;
         | 
| 57 | 
            +
                klass.undef_default_alloc_func();
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                // UNWRAP: We know `MAP_SHARED` fits in a `Fixnum`.
         | 
| 60 | 
            +
                klass.const_set("MAP_SHARED", Fixnum::from_i64(MAP_SHARED).unwrap())?;
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                klass.define_singleton_method("to_metrics", function!(MmapedFile::to_metrics, 1))?;
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                // Required for subclassing to work
         | 
| 65 | 
            +
                klass.define_alloc_func::<MmapedFile>();
         | 
| 66 | 
            +
                klass.define_singleton_method("new", method!(MmapedFile::new, -1))?;
         | 
| 67 | 
            +
                klass.define_method("initialize", method!(MmapedFile::initialize, 1))?;
         | 
| 68 | 
            +
                klass.define_method("slice", method!(MmapedFile::slice, -1))?;
         | 
| 69 | 
            +
                klass.define_method("sync", method!(MmapedFile::sync, -1))?;
         | 
| 70 | 
            +
                klass.define_method("munmap", method!(MmapedFile::munmap, 0))?;
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                klass.define_method("used", method!(MmapedFile::load_used, 0))?;
         | 
| 73 | 
            +
                klass.define_method("used=", method!(MmapedFile::save_used, 1))?;
         | 
| 74 | 
            +
                klass.define_method("fetch_entry", method!(MmapedFile::fetch_entry, 3))?;
         | 
| 75 | 
            +
                klass.define_method("upsert_entry", method!(MmapedFile::upsert_entry, 3))?;
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                Ok(())
         | 
| 78 | 
            +
            }
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #[macro_export]
         | 
| 2 | 
            +
            macro_rules! err {
         | 
| 3 | 
            +
                (with_errno: $err_t:expr, $($arg:expr),*) => {
         | 
| 4 | 
            +
                    {
         | 
| 5 | 
            +
                        let err = format!($($arg),*);
         | 
| 6 | 
            +
                        let strerror = strerror(errno());
         | 
| 7 | 
            +
                        Error::new($err_t, format!("{err} ({strerror})"))
         | 
| 8 | 
            +
                    }
         | 
| 9 | 
            +
                };
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                ($err_t:expr, $($arg:expr),*) => {
         | 
| 12 | 
            +
                    Error::new($err_t, format!($($arg),*))
         | 
| 13 | 
            +
                };
         | 
| 14 | 
            +
            }
         |