Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Commit

Permalink
Enable Modularisation (#23)
Browse files Browse the repository at this point in the history
* Refactor rust library into crates

* Refactor library to make the store properties of logins and list rather than logins and list properties of store.
Also provide a Toodle interface through which to instantiate logins and list

* Update iOS project to reflect new library structure

* Address review comments @rnewman.
* Better description for library in Cargo.toml
* Nicer result handling in login and list managers. Couldn't get the "when_ok" ResultEffect working properly. Will take a deeper look

*  Rename ComplexRust.xcodeproj to Toodle.xcodeproj  (#26)

* Rename ComplexRust.xcodeproj to Toodle.xcodeproj

* Rename source code folder to Toodle

* Rollback accidental changes to `ListManager`

These changes were part of the "Enable Async" issue (#4) and accidentally made their way into this commit when renaming the iOS source code folder.
  • Loading branch information
Emily Toop authored Nov 15, 2017
1 parent b15c292 commit 6c0636d
Show file tree
Hide file tree
Showing 44 changed files with 791 additions and 668 deletions.
83 changes: 60 additions & 23 deletions complex objects/cargo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 15 additions & 17 deletions complex objects/cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
[package]
name = "greetings"
version = "0.1.1"
authors = ["fluffyemily <[email protected]>"]
description = "Example static library project built for iOS"
publish = false

[target.'cfg(target_os="android")'.dependencies]
jni = { version = "0.5", default-features = false }
name = "toodle"
version = "0.1.0"
authors = ["Emily Toop <[email protected]>"]
description = "Cross Platform Library for providing To Do List data"

[lib]
name = "greetings"
name = "toodle"
crate-type = ["staticlib", "cdylib"]

[dependencies]
time = "0.1.38"
uuid = { version = "0.4", features = ["v4"] }
libc = "0.2.32"
[dependencies.ffi-utils]
path = "ffi-utils"

[dependencies.store]
path = "store"

[dependencies.logins]
path = "logins"

[dependencies.rusqlite]
version = "0.12"
# System sqlite might be very old.
features = ["bundled", "limits"]
[dependencies.list]
path = "list"
6 changes: 6 additions & 0 deletions complex objects/cargo/ffi-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "ffi-utils"
version = "0.1.0"
authors = ["Emily Toop <[email protected]>"]

[dependencies]
30 changes: 30 additions & 0 deletions complex objects/cargo/ffi-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2016 Mozilla
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

pub mod strings {
use std::os::raw::c_char;
use std::ffi::{
CString,
CStr
};

pub fn c_char_to_string(cchar: *const c_char) -> String {
let c_str = unsafe { CStr::from_ptr(cchar) };
let r_str = match c_str.to_str() {
Err(_) => "",
Ok(string) => string,
};
r_str.to_string()
}

pub fn string_to_c_char(r_string: String) -> *mut c_char {
CString::new(r_string).unwrap().into_raw()
}
}
23 changes: 23 additions & 0 deletions complex objects/cargo/list/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "list"
version = "0.1.0"
authors = ["Emily Toop <[email protected]>"]

[target.'cfg(target_os="android")'.dependencies]
jni = { version = "0.5", default-features = false }

[dependencies]
time = "0.1.38"
uuid = { version = "0.4", features = ["v4"] }
libc = "0.2.32"

[dependencies.store]
path = "../store"

[dependencies.ffi-utils]
path = "../ffi-utils"

[dependencies.rusqlite]
version = "0.12"
# System sqlite might be very old.
features = ["bundled", "limits"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

#import "items.h"

struct category_manager;
struct list_manager;
struct category;
struct item;

const struct category** get_all_categories(const struct category_manager* manager);
const void category_manager_create_item(const struct category_manager* manager, const struct item *item, size_t category_id);
const void category_manager_update_item(const struct category_manager* manager, const struct item *item);
const struct category** get_all_categories(const struct list_manager* manager);
const void category_manager_create_item(const struct list_manager* manager, const struct item *item, size_t category_id);
const void category_manager_update_item(const struct list_manager* manager, const struct item *item);

const size_t category_list_count(const struct category** list);
const void category_list_destroy(const struct category** list);
const struct category* category_list_item_at(const struct category** list, size_t index);
const void add_category(const struct category** list, const struct category* category);

struct category* category_new(const struct category_manager* manager, const char* name);
struct category* category_new(const struct list_manager* manager, const char* name);
const void category_destroy(const struct category* category);
const size_t category_get_id(const struct category* category);
const char* category_get_name(const struct category* category);
Expand Down
File renamed without changes.
Loading

0 comments on commit 6c0636d

Please sign in to comment.