Skip to content

Commit

Permalink
Prepare flatdata release: Fix latest warnings, bump version (#241)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Vetter <[email protected]>
  • Loading branch information
VeaaC authored Aug 30, 2023
1 parent abde70e commit 494f773
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion flatdata-rs/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flatdata"
version = "0.5.4"
version = "0.5.5"
authors = ["boxdot <[email protected]>", "Christian Vetter <[email protected]>", "Gabriel Féron <[email protected]>"]
license = "Apache-2.0"
description = "Rust implementation of flatdata"
Expand Down
4 changes: 1 addition & 3 deletions flatdata-rs/lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -44,8 +45,6 @@ pub enum ResourceStorageError {
},
/// A resource / archive is missing completely
Missing,
#[doc(hidden)]
__Nonexhaustive,
}

impl ResourceStorageError {
Expand Down Expand Up @@ -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",
}
}
}
2 changes: 1 addition & 1 deletion flatdata-rs/lib/src/filestorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
12 changes: 6 additions & 6 deletions flatdata-rs/lib/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -108,15 +108,15 @@ 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;
}

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
Expand All @@ -134,7 +134,7 @@ pub fn generate(
.arg("-g")
.arg("rust")
.arg("-s")
.arg(&entry.path())
.arg(entry.path())
.arg("-O")
.arg(&result)
.spawn()
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion flatdata-rs/lib/src/memstorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Stream>, io::Error> {
Expand Down
2 changes: 1 addition & 1 deletion flatdata-rs/lib/src/multiarrayview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ where
if !self.data.is_empty() {
let type_index = self.data[0];
self.data = &self.data[1..];
let res = <Ts as VariadicStruct>::create(type_index, &self.data);
let res = <Ts as VariadicStruct>::create(type_index, self.data);
self.data = &self.data[res.size_in_bytes()..];
Some(res)
} else {
Expand Down
3 changes: 3 additions & 0 deletions flatdata-rs/lib/src/rawdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions flatdata-rs/lib/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
2 changes: 1 addition & 1 deletion flatdata-rs/lib/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 494f773

Please sign in to comment.