Skip to content

Commit

Permalink
Rewrote RCow to make it covariant instead of invariant.
Browse files Browse the repository at this point in the history
Fixing the lifetime issues (WRT RCow) in
#75

Changed how `RCow` is represented, requiring uses of the `RCow` type to be updated.

Added `RCowVal`, `RCowStr`, and `RCowSlice` type aliases to make `RCow` usable.

Updated uses of `RCow` in `abi_stable` to make it compile,
the repository will be fixed in a latter commit.

Updated RCow tests.

Added tests for comparison traits, conversion traits.

Added `IntoOwned` trait.

Made the comparison traits accept RCows with different type arguments.

Added these conversion impls:
- `From<&'a RVec<T>> for RCowSlice<'a, T>`
- `From<&'a Vec<T>> for RCowSlice<'a, T>`

Now the conversion impls between `Cow` and `RCow` are non-trivial,
using the new `RCowCompatibleRef` trait to simplify some bounds.

Now `RCow` only implements `IntoReprRust`/`AsRef`/`Borrow` for
`RCowVal`, `RCowSlice`, and `RCowStr`.

Removed `BorrowOwned` trait.
  • Loading branch information
rodrimati1992 committed Feb 21, 2022
1 parent 76c49a5 commit 8e1a54d
Show file tree
Hide file tree
Showing 17 changed files with 577 additions and 342 deletions.
22 changes: 11 additions & 11 deletions abi_stable/src/abi_stability/extra_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
//! marker_type::UnsafeIgnoredType,
//! sabi_extern_fn,
//! sabi_trait::prelude::TD_Opaque,
//! std_types::{RCow, ROption, RResult, RSome, RStr},
//! std_types::{RCowSlice, ROption, RResult, RSome, RStr},
//! type_layout::TypeLayout,
//! GetStaticEquivalent, StableAbi,
//! };
Expand Down Expand Up @@ -219,8 +219,8 @@
//! })
//! }
//!
//! fn nested_type_layouts(&self) -> RCow<'_, [&'static TypeLayout]> {
//! RCow::from_slice(&[])
//! fn nested_type_layouts(&self) -> RCowSlice<'_, &'static TypeLayout> {
//! RCowSlice::from(&[])
//! }
//!
//! fn combine(
Expand Down Expand Up @@ -292,7 +292,7 @@
//! },
//! sabi_extern_fn,
//! sabi_trait::prelude::TD_Opaque,
//! std_types::{RCow, RDuration, ROption, RResult, RStr, RString},
//! std_types::{RCowSlice, RDuration, ROption, RResult, RStr, RString},
//! type_layout::TypeLayout,
//! StableAbi,
//! };
Expand Down Expand Up @@ -374,8 +374,8 @@
//! })
//! }
//!
//! fn nested_type_layouts(&self) -> RCow<'_, [&'static TypeLayout]> {
//! RCow::from_slice(&[])
//! fn nested_type_layouts(&self) -> RCowSlice<'_, &'static TypeLayout> {
//! RCowSlice::from(&[])
//! }
//! }
//!
Expand Down Expand Up @@ -421,7 +421,7 @@
//! marker_type::UnsafeIgnoredType,
//! sabi_extern_fn,
//! sabi_trait::prelude::TD_Opaque,
//! std_types::{RCow, RDuration, RResult, RStr, RString},
//! std_types::{RCowSlice, RDuration, RResult, RStr, RString},
//! type_layout::TypeLayout,
//! GetStaticEquivalent, StableAbi,
//! };
Expand Down Expand Up @@ -558,8 +558,8 @@
//! })
//! }
//!
//! fn nested_type_layouts(&self) -> RCow<'_, [&'static TypeLayout]> {
//! RCow::from_slice(&[])
//! fn nested_type_layouts(&self) -> RCowSlice<'_, &'static TypeLayout> {
//! RCowSlice::from(&[])
//! }
//! }
//!
Expand Down Expand Up @@ -592,7 +592,7 @@
use crate::{
rtry, sabi_trait,
sabi_types::{RMut, RRef},
std_types::{RBox, RBoxError, RCow, RNone, ROk, ROption, RResult},
std_types::{RBox, RBoxError, RCowSlice, RNone, ROk, ROption, RResult},
traits::IntoReprC,
type_layout::TypeLayout,
StableAbi,
Expand Down Expand Up @@ -706,7 +706,7 @@ pub unsafe trait ExtraChecks: 'static + Debug + Display + Clone + Send + Sync {
/// Returns the `TypeLayout`s owned or referenced by `self`.
///
/// This is necessary for the Debug implementation of `TypeLayout`.
fn nested_type_layouts(&self) -> RCow<'_, [&'static TypeLayout]>;
fn nested_type_layouts(&self) -> RCowSlice<'_, &'static TypeLayout>;

/// Combines this ExtraChecks trait object with another one.
///
Expand Down
6 changes: 3 additions & 3 deletions abi_stable/src/erased_types/enabled_traits_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! declare_enabled_traits {
ForExtraChecksImplementor,ExtraChecksError,
},
type_layout::TypeLayout,
std_types::{RCow,RResult},
std_types::{RCowSlice,RResult},
StableAbi,
};

Expand Down Expand Up @@ -129,8 +129,8 @@ macro_rules! declare_enabled_traits {
})
}

fn nested_type_layouts(&self)->RCow<'_,[&'static TypeLayout]>{
RCow::from_slice(&[])
fn nested_type_layouts(&self)->RCowSlice<'_, &'static TypeLayout>{
RCowSlice::from_slice(&[])
}
}

Expand Down
12 changes: 6 additions & 6 deletions abi_stable/src/multikey_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,15 @@ mod tests {

let (ret, ret_discr) = map.get_or_insert(10, 1).split();
*ret.value = 1234;
assert_matches!(InsertionTime::Now { .. } = ret_discr);
assert_matches!(ret_discr, InsertionTime::Now { .. });

assert_matches!(
(&mut 1234, InsertionTime::Before { .. }) =
map.get_or_insert(10, 2).map(|x| x.value).split()
map.get_or_insert(10, 2).map(|x| x.value).split(),
(&mut 1234, InsertionTime::Before { .. })
);
assert_matches!(
(&mut 1234, InsertionTime::Before { .. }) =
map.get_or_insert(10, 3).map(|x| x.value).split()
map.get_or_insert(10, 3).map(|x| x.value).split(),
(&mut 1234, InsertionTime::Before { .. })
);
}

Expand All @@ -491,7 +491,7 @@ mod tests {
let (ret, ret_discr) = map.get_or_insert(100, 1).split();
let index0 = ret.index;
*ret.value = 1234;
assert_matches!(InsertionTime::Now { .. } = ret_discr);
assert_matches!(ret_discr, InsertionTime::Now { .. });

let index1 = map.get_or_insert(200, 200).into_inner().index;
let index2 = map.get_or_insert(300, 300).into_inner().index;
Expand Down
2 changes: 1 addition & 1 deletion abi_stable/src/std_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub use self::{
arc::RArc,
boxed::RBox,
cmp_ordering::RCmpOrdering,
cow::RCow,
cow::{RCow, RCowSlice, RCowStr, RCowVal},
map::RHashMap,
option::{RNone, ROption, RSome},
result::{RErr, ROk, RResult},
Expand Down
Loading

0 comments on commit 8e1a54d

Please sign in to comment.