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

Split tuples, arrays and the C API off from the records file and refactored them #872

Merged
merged 3 commits into from
Dec 22, 2020
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.com/vmware/differential-datalog.svg?branch=master)](https://travis-ci.com/vmware/differential-datalog)
[![pipeline status](https://gitlab.com/ddlog/differential-datalog/badges/master/pipeline.svg)](https://gitlab.com/ddlog/differential-datalog/commits/master)
[![rustc](https://img.shields.io/badge/rustc-1.41+-blue.svg)](https://blog.rust-lang.org/2020/03/12/Rust-1.42.html)
[![rustc](https://img.shields.io/badge/rustc-1.47+-blue.svg)](https://blog.rust-lang.org/2020/10/08/Rust-1.47.html)
[![Gitter chat](https://badges.gitter.im/vmware/differential-datalog.png)](https://gitter.im/vmware/differential-datalog)

# Differential Datalog (DDlog)
Expand Down Expand Up @@ -96,7 +96,7 @@ You are now ready to [start coding in DDlog](doc/tutorial/tutorial.md).
```
wget -qO- https://get.haskellstack.org/ | sh
```
- Rust toolchain v1.41 or later:
- Rust toolchain v1.47 or later:
```
curl https://sh.rustup.rs -sSf | sh
. $HOME/.cargo/env
Expand Down
7 changes: 1 addition & 6 deletions rust/template/differential_datalog/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#![allow(
clippy::unknown_clippy_lints,
clippy::get_unwrap,
clippy::missing_safety_doc,
clippy::type_complexity,
clippy::match_like_matches_macro,
// match_like_matches_macro not supported in older versions of clippy
clippy::unknown_clippy_lints,
// required because of a bug in older clippy (1.41).
clippy::useless_let_if_seq
clippy::match_like_matches_macro
)]

mod callback;
Expand Down
61 changes: 61 additions & 0 deletions rust/template/differential_datalog/src/record/arrays.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! Implementing `Record`-related traits for Rust arrays

use crate::record::{CollectionKind, FromRecord, IntoRecord, Mutator, Record};
use std::result::Result;

/// Implements `FromRecord`, `IntoRecord` and `Mutator` for arrays
// FIXME: Replace this with `min_const_generics` after Rust v1.50
// https://github.com/rust-lang/rust/issues/74878
macro_rules! ddlog_array_traits {
($($length:literal),* $(,)?) => {
$(
impl<T: FromRecord + Default> FromRecord for [T; $length] {
fn from_record(val: &Record) -> Result<Self, String> {
let vec = Vec::from_record(val)?;
let mut arr = <[T; $length]>::default();

if vec.len() != $length {
return Err(format!(
"cannot convert {:?} to array of length {}",
*val, $length
));
};
let mut idx = 0;
for v in vec.into_iter() {
arr[idx] = v;
idx += 1;
}
Ok(arr)

// Simpler implementation that requires Rust 1.48:
// Vec::from_record(val)?.try_into().map_err(|_| {
// format!("cannot convert {:?} to array of length {}", *val, $length)
// })
}
}

impl<T: IntoRecord + Clone> IntoRecord for [T; $length] {
fn into_record(self) -> Record {
Record::Array(
CollectionKind::Vector,
self.iter().cloned().map(IntoRecord::into_record).collect(),
)
}
}

impl<T: FromRecord + Default> Mutator<[T; $length]> for Record {
fn mutate(&self, array: &mut [T; $length]) -> Result<(), String> {
*array = <[T; $length]>::from_record(self)?;
Ok(())
}
}
)*
};
}

ddlog_array_traits! {
0, 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,
}
Loading