diff --git a/flatdata-rs/lib/Cargo.toml b/flatdata-rs/lib/Cargo.toml index 440e5a9d..cfe374db 100644 --- a/flatdata-rs/lib/Cargo.toml +++ b/flatdata-rs/lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "flatdata" -version = "0.5.4" +version = "0.5.5" authors = ["boxdot ", "Christian Vetter ", "Gabriel FĂ©ron "] license = "Apache-2.0" description = "Rust implementation of flatdata" diff --git a/flatdata-rs/lib/src/error.rs b/flatdata-rs/lib/src/error.rs index a2b3af8c..463407bc 100644 --- a/flatdata-rs/lib/src/error.rs +++ b/flatdata-rs/lib/src/error.rs @@ -5,6 +5,7 @@ use std::{error, fmt, io, str::Utf8Error}; /// /// [`Storage`]: trait.Storage.html #[derive(Debug)] +#[non_exhaustive] pub enum ResourceStorageError { /// Wrapper of [`io::Error`] with resource name for which the error /// occurred. @@ -44,8 +45,6 @@ pub enum ResourceStorageError { }, /// A resource / archive is missing completely Missing, - #[doc(hidden)] - __Nonexhaustive, } impl ResourceStorageError { @@ -74,7 +73,6 @@ impl error::Error for ResourceStorageError { ResourceStorageError::WrongSignature { .. } => "schema is not matching expected schema", ResourceStorageError::TooBig { .. } => "resource is too big", ResourceStorageError::Missing => "Missing resource / archive", - ResourceStorageError::__Nonexhaustive => "n/a", } } } diff --git a/flatdata-rs/lib/src/filestorage.rs b/flatdata-rs/lib/src/filestorage.rs index 0664dcd4..8e1e14d9 100644 --- a/flatdata-rs/lib/src/filestorage.rs +++ b/flatdata-rs/lib/src/filestorage.rs @@ -28,7 +28,7 @@ impl MemoryMappedFileStorage { // We cannot prove to Rust that the buffer will live as long as the storage // (we never delete mappings), so we need to manually extend lifetime let extended_lifetime_data = unsafe { slice::from_raw_parts(data.as_ptr(), data.len()) }; - Ok(&extended_lifetime_data) + Ok(extended_lifetime_data) } } diff --git a/flatdata-rs/lib/src/generator.rs b/flatdata-rs/lib/src/generator.rs index 6ef01bb0..45ebd572 100644 --- a/flatdata-rs/lib/src/generator.rs +++ b/flatdata-rs/lib/src/generator.rs @@ -59,9 +59,9 @@ use std::{ /// If you are working on the generator, you can make sure your `build.rs` /// script picks up the source by setting `FLATDATA_GENERATOR_PATH` to point to /// the `flatdata-generator` folder. -/// +/// /// ## Build -/// +/// /// This method will try to install flatdata-generator in a python venv automatically /// You can provide your own generator by setting `FLATDATA_GENERATOR_BIN` to point to /// the `flatdata-generator` binary. @@ -108,7 +108,7 @@ pub fn generate( out_dir.join("bin/flatdata-generator") }; - for entry in walkdir::WalkDir::new(&schemas_path) { + for entry in walkdir::WalkDir::new(schemas_path) { let entry = entry?; if entry.path().extension().map_or(true, |x| x != "flatdata") { continue; @@ -116,7 +116,7 @@ pub fn generate( let result: PathBuf = if schemas_path.is_dir() { out_dir - .join(entry.path().strip_prefix(&schemas_path).unwrap()) + .join(entry.path().strip_prefix(schemas_path).unwrap()) .with_extension("rs") } else { out_dir @@ -134,7 +134,7 @@ pub fn generate( .arg("-g") .arg("rust") .arg("-s") - .arg(&entry.path()) + .arg(entry.path()) .arg("-O") .arg(&result) .spawn() @@ -184,7 +184,7 @@ pub enum GeneratorError { } impl std::fmt::Display for GeneratorError { - fn fmt(self: &Self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { match self { GeneratorError::PythonError(err) => { writeln!(f, "{} could not be executed", err)?; diff --git a/flatdata-rs/lib/src/memstorage.rs b/flatdata-rs/lib/src/memstorage.rs index 7d990e72..04fdee21 100644 --- a/flatdata-rs/lib/src/memstorage.rs +++ b/flatdata-rs/lib/src/memstorage.rs @@ -138,7 +138,7 @@ impl ResourceStorage for MemoryResourceStorage { // We cannot prove to Rust that the buffer will live as long as the storage // (we never delete mappings), so we need to manually extend lifetime let extended_lifetime_data = unsafe { slice::from_raw_parts(data.as_ptr(), data.len()) }; - Ok(&extended_lifetime_data) + Ok(extended_lifetime_data) } fn create_output_stream(&self, resource_name: &str) -> Result, io::Error> { diff --git a/flatdata-rs/lib/src/multiarrayview.rs b/flatdata-rs/lib/src/multiarrayview.rs index a0da9f94..848a8a01 100644 --- a/flatdata-rs/lib/src/multiarrayview.rs +++ b/flatdata-rs/lib/src/multiarrayview.rs @@ -102,7 +102,7 @@ where if !self.data.is_empty() { let type_index = self.data[0]; self.data = &self.data[1..]; - let res = ::create(type_index, &self.data); + let res = ::create(type_index, self.data); self.data = &self.data[res.size_in_bytes()..]; Some(res) } else { diff --git a/flatdata-rs/lib/src/rawdata.rs b/flatdata-rs/lib/src/rawdata.rs index 1b440e2d..b8d5ff2e 100644 --- a/flatdata-rs/lib/src/rawdata.rs +++ b/flatdata-rs/lib/src/rawdata.rs @@ -44,6 +44,9 @@ impl<'a> RawData<'a> { /// Reads a \0 terminated substring starting at specified offset without checking that the /// string contains valid UTF-8. + /// + /// # Safety + /// Same as str::from_utf8_unchecked #[inline] pub unsafe fn substring_unchecked(&self, start: usize) -> &'a str { self.substring_with(start, |bytes| str::from_utf8_unchecked(bytes)) diff --git a/flatdata-rs/lib/src/structs.rs b/flatdata-rs/lib/src/structs.rs index 00fe3ba0..2e8a04d2 100644 --- a/flatdata-rs/lib/src/structs.rs +++ b/flatdata-rs/lib/src/structs.rs @@ -52,6 +52,11 @@ pub trait Struct: Debug { } /// Marks structs that can be used stand-alone, e.g. no range +/// +/// # Safety +/// +/// Safe only if the struct does not any memory outside of its own memory range +/// E.g. @range annotations use the next struct's memory and must not implement this pub unsafe trait NoOverlap {} /// Marks structs that cannot be used stand-alone, e.g. no range pub trait Overlap {} diff --git a/flatdata-rs/lib/src/vector.rs b/flatdata-rs/lib/src/vector.rs index 315f895c..5efe7ceb 100644 --- a/flatdata-rs/lib/src/vector.rs +++ b/flatdata-rs/lib/src/vector.rs @@ -296,7 +296,7 @@ where fn flush(&mut self) -> io::Result<()> { self.resource_handle .borrow_mut() - .write(&self.data.as_view().as_bytes())?; + .write(self.data.as_view().as_bytes())?; self.data.clear(); Ok(()) }