Skip to content

Commit

Permalink
Add trait bound for U and V
Browse files Browse the repository at this point in the history
  • Loading branch information
CoorFun authored and anthonyray committed Mar 23, 2020
1 parent a91c61c commit 51e1400
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions ffi-convert/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ impl CDrop for CStringArray {
/// let ctoppings = CArray::<CPizzaTopping>::c_repr_of(toppings);
///
/// ```
///
///
#[repr(C)]
pub struct CArray<T> {
data_ptr: *const T,
Expand Down Expand Up @@ -180,7 +178,7 @@ impl<T> Drop for CArray<T> {
/// pub range: Range<i32>
/// }
///
/// #[derive(AsRust CDrop, CReprOf, Debug, PartialEq)]
/// #[derive(AsRust, CDrop, CReprOf, Debug, PartialEq)]
/// #[target_type(Foo)]
/// pub struct CFoo {
/// pub range: CRange<i32>
Expand All @@ -205,18 +203,15 @@ impl<T> Drop for CArray<T> {
///
/// let foo_converted = c_foo.as_rust().unwrap();
/// assert_eq!(foo_converted, foo);
///
/// ```
///
///
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
pub struct CRange<T> {
pub start: T,
pub end: T,
}

impl<U: AsRust<V>, V> AsRust<Range<V>> for CRange<U> {
impl<U: AsRust<V> + PartialOrd, V: PartialOrd> AsRust<Range<V>> for CRange<U> {
fn as_rust(&self) -> Result<Range<V>, Error> {
Ok(Range {
start: self.start.as_rust()?,
Expand All @@ -225,7 +220,7 @@ impl<U: AsRust<V>, V> AsRust<Range<V>> for CRange<U> {
}
}

impl<U: CReprOf<V> + CDrop, V> CReprOf<Range<V>> for CRange<U> {
impl<U: CReprOf<V> + PartialOrd + CDrop, V: PartialOrd> CReprOf<Range<V>> for CRange<U> {
fn c_repr_of(input: Range<V>) -> Result<Self, Error> {
Ok(Self {
start: U::c_repr_of(input.start)?,
Expand All @@ -244,4 +239,4 @@ impl<T> Drop for CRange<T> {
fn drop(&mut self) {
let _ = self.do_drop();
}
}
}

0 comments on commit 51e1400

Please sign in to comment.