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

Prepare flatdata release: Fix latest warnings, bump version #241

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <d@zerovolt.org>", "Christian Vetter <veaac.fdirct@gmail.com>", "Gabriel Féron <feron.gabriel@gmail.com>"]
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
Loading