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

Cargo first #711

Draft
wants to merge 4 commits into
base: 3.0
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ venv

# Cargo files #
Cargo.lock
Cargo.toml

# Temporary paket files for C# #
paket-files/
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

[workspace]
resolver = "2"
members = ["rust", "rust/tests/behaviour/config", "rust/tests/behaviour/steps", "c"]

40 changes: 40 additions & 0 deletions c/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

# Generated by Vaticle Cargo sync tool.

features = {}

[package]
name = "typedb_driver_clib"
edition = "2021"
version = "0.0.0"

[lib]
path = "src/lib.rs"

[dependencies]

[dependencies.env_logger]
features = ["auto-color", "color", "default", "humantime", "regex"]
version = "0.10.2"
default-features = false

[dependencies.log]
features = ["kv", "kv_unstable", "std", "value-bag"]
version = "0.4.22"
default-features = false

[dependencies.typedb-driver]
path = "../rust"
features = ["sync"]
default-features = false

[dependencies.chrono]
features = ["alloc", "android-tzdata", "clock", "default", "iana-time-zone", "js-sys", "now", "oldtime", "serde", "std", "wasm-bindgen", "wasmbind", "winapi", "windows-targets"]
version = "0.4.38"
default-features = false

[dependencies.itertools]
features = ["default", "use_alloc", "use_std"]
version = "0.10.5"
default-features = false

4 changes: 2 additions & 2 deletions c/src/answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct QueryAnswerPromise(BoxPromise<'static, Result<QueryAnswer>>);

impl QueryAnswerPromise {
pub fn new(promise: impl Promise<'static, Result<QueryAnswer>>) -> Self {
Self(Box::new(|| Ok(promise.resolve()?)))
Self(Box::new(|| promise.resolve()))
}
}

Expand Down Expand Up @@ -106,7 +106,7 @@ pub extern "C" fn concept_row_drop(concept_row: *mut ConceptRow) {
/// Produces an <code>Iterator</code> over all <code>String</code> column names of the <code>ConceptRow</code>'s header.
#[no_mangle]
pub extern "C" fn concept_row_get_column_names(concept_row: *const ConceptRow) -> *mut StringIterator {
release(StringIterator(CIterator(box_stream(borrow(concept_row).get_column_names().into_iter().cloned().map(Ok)))))
release(StringIterator(CIterator(box_stream(borrow(concept_row).get_column_names().iter().cloned().map(Ok)))))
}

/// Retrieve the executed query's type of the <code>ConceptRow</code>'s header.
Expand Down
24 changes: 12 additions & 12 deletions c/src/concept/concept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub extern "C" fn string_and_opt_value_drop(string_and_opt_value: *mut StringAnd
/// Otherwise, returns <code>false</code>.
#[no_mangle]
pub extern "C" fn attribute_type_is_untyped(attribute_type: *const Concept) -> bool {
matches!(borrow_as_attribute_type(attribute_type).value_type, None)
borrow_as_attribute_type(attribute_type).value_type.is_none()
}

/// Returns <code>true</code> if the attribute type is of type <code>boolean</code>.
Expand Down Expand Up @@ -306,8 +306,8 @@ pub extern "C" fn value_is_struct(value: *const Concept) -> bool {
/// If the value has another type, the error is set.
#[no_mangle]
pub extern "C" fn value_get_boolean(value: *const Concept) -> bool {
if let Value::Boolean(bool) = borrow_as_value(value) {
*bool
if let &Value::Boolean(bool) = borrow_as_value(value) {
bool
} else {
unreachable!("Attempting to unwrap a non-boolean {:?} as boolean", borrow_as_value(value))
}
Expand All @@ -317,8 +317,8 @@ pub extern "C" fn value_get_boolean(value: *const Concept) -> bool {
/// If the value has another type, the error is set.
#[no_mangle]
pub extern "C" fn value_get_long(value: *const Concept) -> i64 {
if let Value::Long(long) = borrow_as_value(value) {
*long
if let &Value::Long(long) = borrow_as_value(value) {
long
} else {
unreachable!("Attempting to unwrap a non-long {:?} as long", borrow_as_value(value))
}
Expand All @@ -328,8 +328,8 @@ pub extern "C" fn value_get_long(value: *const Concept) -> i64 {
/// If the value has another type, the error is set.
#[no_mangle]
pub extern "C" fn value_get_double(value: *const Concept) -> f64 {
if let Value::Double(double) = borrow_as_value(value) {
*double
if let &Value::Double(double) = borrow_as_value(value) {
double
} else {
unreachable!("Attempting to unwrap a non-double {:?} as double", borrow_as_value(value))
}
Expand All @@ -339,8 +339,8 @@ pub extern "C" fn value_get_double(value: *const Concept) -> f64 {
/// If the value has another type, the error is set.
#[no_mangle]
pub extern "C" fn value_get_decimal(value: *const Concept) -> Decimal {
if let Value::Decimal(decimal) = borrow_as_value(value) {
decimal.clone()
if let &Value::Decimal(decimal) = borrow_as_value(value) {
decimal
} else {
unreachable!("Attempting to unwrap a non-decimal {:?} as decimal", borrow_as_value(value))
}
Expand Down Expand Up @@ -394,8 +394,8 @@ pub extern "C" fn value_get_datetime_tz(value: *const Concept) -> DatetimeAndTim
/// If the value has another type, the error is set.
#[no_mangle]
pub extern "C" fn value_get_duration(value: *const Concept) -> Duration {
if let Value::Duration(duration) = borrow_as_value(value) {
duration.clone()
if let &Value::Duration(duration) = borrow_as_value(value) {
duration
} else {
unreachable!("Attempting to unwrap a non-duration {:?} as duration", borrow_as_value(value))
}
Expand Down Expand Up @@ -483,7 +483,7 @@ pub extern "C" fn concept_is_role_type(concept: *const Concept) -> bool {
/// Gets the 'label' of this <code>Concept</code> object.
#[no_mangle]
pub extern "C" fn concept_get_label(concept: *const Concept) -> *mut c_char {
release_string(borrow(concept).get_label().clone().to_owned())
release_string(borrow(concept).get_label().to_owned())
}

/// A string representation of this <code>Concept</code> object.
Expand Down
5 changes: 2 additions & 3 deletions c/src/concept/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

use std::ptr::addr_of_mut;

use itertools::Itertools;
use typedb_driver::{
answer::{ConceptDocument, ConceptRow, QueryAnswer, ValueGroup},
concept::{Attribute, AttributeType, Concept, Entity, EntityType, Relation, RelationType, RoleType, Value},
answer::{ConceptRow, ValueGroup},
concept::Concept,
BoxPromise, Promise, Result,
};

Expand Down
2 changes: 1 addition & 1 deletion c/src/concept/thing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use std::{ffi::c_char, ptr::null_mut};

use typedb_driver::concept::{Concept, Value};
use typedb_driver::concept::Concept;

use super::concept::{borrow_as_attribute, borrow_as_entity, borrow_as_relation};
use crate::memory::{release, release_string};
Expand Down
2 changes: 1 addition & 1 deletion c/src/concept/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::ffi::c_char;

use typedb_driver::concept::Concept;

use super::concept::{borrow_as_attribute_type, borrow_as_entity_type, borrow_as_relation_type, borrow_as_role_type};
use super::concept::borrow_as_attribute_type;
use crate::memory::release_string;

/// Gets the string representation of the value type of this attribute type.
Expand Down
7 changes: 3 additions & 4 deletions c/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
* under the License.
*/

use std::{ffi::c_char, ptr::addr_of_mut, sync::Arc};
use std::ffi::c_char;

use typedb_driver::{box_stream, info::ReplicaInfo, Database};
use typedb_driver::Database;

use super::{
error::{try_release_string, unwrap_void},
iterator::{iterator_next, CIterator},
memory::{borrow, borrow_mut, free, release, release_optional, release_string, take_ownership},
memory::{borrow, release_string},
};
use crate::memory::{decrement_arc, take_arc};

Expand Down
2 changes: 1 addition & 1 deletion c/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use typedb_driver::{Error, Result};
use super::memory::{free, release_arc, release_optional, release_string};

thread_local! {
static LAST_ERROR: RefCell<Option<Error>> = RefCell::new(None);
static LAST_ERROR: RefCell<Option<Error>> = const { RefCell::new(None) };
}

/// Enables logging in the TypeDB driver.
Expand Down
4 changes: 2 additions & 2 deletions c/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
use std::{
cell::RefCell,
ffi::{c_char, CStr, CString},
ptr::{null, null_mut},
ptr::null_mut,
sync::Arc,
};

use log::trace;
use typedb_driver::Error;

thread_local! {
static LAST_ERROR: RefCell<Option<Error>> = RefCell::new(None);
static LAST_ERROR: RefCell<Option<Error>> = const { RefCell::new(None) };
}

pub(super) fn release<T>(t: T) -> *mut T {
Expand Down
6 changes: 0 additions & 6 deletions c/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
* under the License.
*/

use std::time::Duration;

use typedb_driver::Options;

use super::memory::{borrow, borrow_mut, free, release};

// /// Produces a new <code>TypeDBOptions</code> object.
// #[no_mangle]
// pub extern "C" fn options_new() -> *mut Options {
Expand Down
5 changes: 2 additions & 3 deletions c/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use std::{ffi::c_char, ptr::null_mut};

use typedb_driver::{DatabaseManager, Error, Transaction, TransactionType, TypeDBDriver};
use typedb_driver::{Error, Transaction, TransactionType, TypeDBDriver};

use super::memory::{borrow, borrow_mut, free, release, take_ownership};
use crate::{answer::QueryAnswerPromise, error::try_release, memory::string_view, promise::VoidPromise};
Expand Down Expand Up @@ -87,6 +87,5 @@ pub extern "C" fn transaction_on_close(
callback_id: usize,
callback: extern "C" fn(usize, *mut Error),
) {
borrow(txn)
.on_close(move |error| callback(callback_id, error.map(|err| release(err.into())).unwrap_or(null_mut())));
borrow(txn).on_close(move |error| callback(callback_id, error.map(release).unwrap_or(null_mut())));
}
9 changes: 0 additions & 9 deletions c/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
* under the License.
*/

use std::ffi::c_char;

use typedb_driver::{User, UserManager};

use super::{
error::unwrap_void,
memory::{borrow, free, release_string, string_view},
};

// /// Frees the native rust <code>User</code> object.
// #[no_mangle]
// pub extern "C" fn user_drop(user: *mut User) {
Expand Down
10 changes: 0 additions & 10 deletions c/src/user_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
* under the License.
*/

use std::{ffi::c_char, ptr::addr_of_mut};

use typedb_driver::{box_stream, TypeDBDriver, User, UserManager};

use super::{
error::{try_release, try_release_optional, unwrap_or_default, unwrap_void},
iterator::{iterator_next, CIterator},
memory::{borrow, free, release, string_view},
};

// /// Creates a <code>UserManager</code> on the specified connection
// #[no_mangle]
// pub extern "C" fn user_manager_new(connection: *const TypeDBDriver) -> *mut UserManager {
Expand Down
8 changes: 4 additions & 4 deletions dependencies/vaticle/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
def vaticle_dependencies():
git_repository(
name = "vaticle_dependencies",
remote = "https://github.com/typedb/dependencies",
commit = "2acdb27e8f0139e1535855328396654535472703", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
remote = "https://github.com/dmitrii-ubskii/dependencies",
commit = "b4d8e026b06e2ea0d7c461b1b09fba81111c8d76", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
)

def vaticle_typedb_protocol():
git_repository(
name = "vaticle_typedb_protocol",
remote = "https://github.com/typedb/typedb-protocol",
tag = "3.0.0-alpha-7", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_protocol
remote = "https://github.com/dmitrii-ubskii/typedb-protocol",
commit = "71d7975a4617bb142015d27deaa3f8e886c00f0f", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_protocol
)

def vaticle_typedb_behaviour():
Expand Down
Loading