Skip to content

Commit

Permalink
Merge pull request #17 from snipsco/crates_release
Browse files Browse the repository at this point in the history
Release on crates.io
  • Loading branch information
anthonyray authored Mar 17, 2020
2 parents 768c234 + 64fa01a commit 3bc7f8f
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"ffi-utils",
"ffi-utils-derive",
"ffi-utils-tests",
"ffi-convert",
"ffi-convert-derive",
"ffi-convert-tests",
]
18 changes: 18 additions & 0 deletions ffi-convert-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "ffi-convert-derive"
version = "0.1.0"
authors = ["Sonos"]
edition = "2018"
license = "MIT OR Apache-2.0"
description = "Macros implementations of CReprOf, AsRust, CDrop traits from ffi-convert"
repository = "https://github.com/snipsco/snips-utils-rs"
readme = "../README.md"
keywords = ["ffi"]

[lib]
proc-macro = true

[dependencies]
syn = "1.0.5"
quote = "1.0.2"
proc-macro2 = "1.0.6"
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn impl_asrust_macro(input: &syn::DeriveInput) -> TokenStream {
}

let mut conversion = if field.is_string {
quote!( ffi_utils::create_rust_string_from!(self.#field_name) )
quote!( ffi_convert::create_rust_string_from!(self.#field_name) )
} else {
if field.is_pointer {
quote!( {
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn impl_asrust_macro(input: &syn::DeriveInput) -> TokenStream {

quote!(
impl AsRust<#target_type> for #struct_name {
fn as_rust(&self) -> Result<#target_type, ffi_utils::Error> {
fn as_rust(&self) -> Result<#target_type, ffi_convert::Error> {
use failure::ResultExt;
Ok(#target_type {
#(#fields, )*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn impl_cdrop_macro(input: &syn::DeriveInput) -> TokenStream {
} = field;

let drop_field = if field.is_string {
quote!(ffi_utils::take_back_c_string!(self.#field_name))
quote!(ffi_convert::take_back_c_string!(self.#field_name))
} else {
if field.is_pointer {
quote!( unsafe { #field_type::drop_raw_pointer(self.#field_name) }? )
Expand All @@ -42,8 +42,8 @@ pub fn impl_cdrop_macro(input: &syn::DeriveInput) -> TokenStream {

let c_drop_impl = quote!(
impl CDrop for # struct_name {
fn do_drop(&mut self) -> Result<(), ffi_utils::Error> {
use ffi_utils::RawPointerConverter;
fn do_drop(&mut self) -> Result<(), ffi_convert::Error> {
use ffi_convert::RawPointerConverter;
# ( #do_drop_fields; )*
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn impl_creprof_macro(input: &syn::DeriveInput) -> TokenStream {

let c_repr_of_impl = quote!(
impl CReprOf<# target_type> for # struct_name {
fn c_repr_of(input: # target_type) -> Result<Self, ffi_utils::Error> {
fn c_repr_of(input: # target_type) -> Result<Self, ffi_convert::Error> {
use failure::ResultExt;
use ffi_utils::RawPointerConverter;
use ffi_convert::RawPointerConverter;
Ok(Self {
# ( # c_repr_of_fields, )*
})
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions ffi-convert-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "ffi-convert-tests"
version = "0.1.0"
authors = ["Sonos"]
edition = "2018"

[dependencies]
failure = "0.1"
ffi-convert = "0.1"
libc = "0.2.66"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use failure::{bail, Fallible};
use ffi_utils::*;
use ffi_convert::*;

#[macro_export]
macro_rules! generate_round_trip_rust_c_rust {
Expand Down
15 changes: 15 additions & 0 deletions ffi-convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "ffi-convert"
version = "0.1.0"
authors = ["Sonos"]
edition = "2018"
license = "MIT OR Apache-2.0"
description = "A collection of utilities to ease conversion between Rust and C-compatible data structures."
repository = "https://github.com/snipsco/snips-utils-rs"
readme = "../README.md"
keywords = ["ffi"]

[dependencies]
ffi-convert-derive = "0.1"
failure = "0.1"
libc = "0.2"
File renamed without changes.
14 changes: 7 additions & 7 deletions ffi-utils/src/lib.rs → ffi-convert/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//!
//! We then create the C-compatible struct by [mapping](#types-representations-mapping) idiomatic Rust types to C-compatible types :
//! ```
//! # use ffi_utils::CArray;
//! # use ffi_convert::CArray;
//! # struct CTopping {};
//! # struct CSauce {};
//! #[repr(C)]
Expand All @@ -55,9 +55,9 @@
//! Instead of manually writing the body of the conversion traits, we can derive them :
//!
//! ```
//! # use ffi_utils::{CReprOf, AsRust, CDrop};
//! # use ffi_utils::CArray;
//! # use ffi_utils::RawBorrow;
//! # use ffi_convert::{CReprOf, AsRust, CDrop};
//! # use ffi_convert::CArray;
//! # use ffi_convert::RawBorrow;
//! # struct Sauce {};
//! # #[derive(CReprOf, AsRust, CDrop)]
//! # #[target_type(Sauce)]
Expand Down Expand Up @@ -134,7 +134,7 @@
//! The `CReprOf` trait allows to create a C-compatible representation of the reciprocal idiomatic Rust struct by consuming the latter.
//! ```
//! # use ffi_utils::{Error, CDrop};
//! # use ffi_convert::{Error, CDrop};
//! pub trait CReprOf<T>: Sized + CDrop {
//! fn c_repr_of(input: T) -> Result<Self, Error>;
//! }
Expand All @@ -151,7 +151,7 @@
//! The `AsRust` trait allows to create an idiomatic Rust struct from a C-compatible struct :
//! ```
//! # use ffi_utils::{Error, CDrop};
//! # use ffi_convert::{Error, CDrop};
//! pub trait AsRust<T> {
//! fn as_rust(&self) -> Result<T, Error>;
//! }
Expand All @@ -167,7 +167,7 @@
//! ## Caveats with derivation of CReprOf and AsRust traits
//!
pub use ffi_utils_derive::*;
pub use ffi_convert_derive::*;

mod conversions;
mod types;
Expand Down
15 changes: 2 additions & 13 deletions ffi-utils/src/types.rs → ffi-convert/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,11 @@ use crate::conversions::*;
use crate::convert_to_c_string_result;
use crate::create_rust_string_from;

/// Used as a return type for functions that can encounter errors
#[repr(C)]
#[derive(Debug)]
#[allow(non_camel_case_types)]
pub enum SNIPS_RESULT {
/// The function returned successfully
SNIPS_RESULT_OK = 0,
/// The function encountered an error, you can retrieve it using the dedicated function
SNIPS_RESULT_KO = 1,
}

/// A utility type to represent arrays of string
/// # Example
///
/// ```
/// use ffi_utils::{CReprOf, CStringArray};
/// use ffi_convert::{CReprOf, CStringArray};
/// let pizza_names = vec!["Diavola".to_string(), "Margarita".to_string(), "Regina".to_string()];
/// let c_pizza_names = CStringArray::c_repr_of(pizza_names).expect("could not convert !");
///
Expand Down Expand Up @@ -95,7 +84,7 @@ impl CDrop for CStringArray {
/// # Example
///
/// ```
/// use ffi_utils::{CReprOf, AsRust, CDrop, CArray};
/// use ffi_convert::{CReprOf, AsRust, CDrop, CArray};
/// use libc::c_char;
///
/// pub struct PizzaTopping {
Expand Down
13 changes: 0 additions & 13 deletions ffi-utils-derive/Cargo.toml

This file was deleted.

10 changes: 0 additions & 10 deletions ffi-utils-tests/Cargo.toml

This file was deleted.

13 changes: 0 additions & 13 deletions ffi-utils/Cargo.toml

This file was deleted.

0 comments on commit 3bc7f8f

Please sign in to comment.