Skip to content

Commit

Permalink
Removed IdSlice trait.
Browse files Browse the repository at this point in the history
It won't work without unsafe_no_drop_flag which can't be used in stable
rust.
  • Loading branch information
SSheldon committed Mar 5, 2015
1 parent f4d3044 commit 4118e96
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
19 changes: 0 additions & 19 deletions core/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,6 @@ impl<T, O> fmt::Debug for Id<T, O> where T: fmt::Debug {
/// A convenient alias for a shared `Id`.
pub type ShareId<T> = Id<T, Shared>;

/// Extension methods for slices containing `Id`s.
pub trait IdSlice {
/// The type of the items in the slice.
type Item;

/// Convert a slice of `Id`s into a slice of references
fn as_refs_slice(&self) -> &[&Self::Item];
}

impl<T, O> IdSlice for [Id<T, O>] {
type Item = T;

fn as_refs_slice(&self) -> &[&T] {
unsafe {
mem::transmute(self)
}
}
}

#[cfg(test)]
mod tests {
use std::mem;
Expand Down
2 changes: 1 addition & 1 deletion core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern crate malloc_buf;
#[cfg(test)]
extern crate objc_test_utils;

pub use id::{Id, IdSlice, Owned, Ownership, Shared, ShareId};
pub use id::{Id, Owned, Ownership, Shared, ShareId};
pub use encode::{encode, Encode, EncodePtr};
pub use message::{send_message, send_super_message, Message, MessageArguments, ToMessage};
pub use weak::WeakId;
Expand Down
10 changes: 5 additions & 5 deletions foundation/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cmp::Ordering;
use std::marker::PhantomData;
use std::ops::{Index, Range};

use objc::{Id, IdSlice, Owned, Ownership, Shared, ShareId};
use objc::{Id, Owned, Ownership, Shared, ShareId};
use objc::runtime::{Class, Object};

use {INSCopying, INSFastEnumeration, INSMutableCopying, INSObject, NSEnumerator};
Expand Down Expand Up @@ -98,9 +98,9 @@ pub trait INSArray : INSObject {
}

fn from_vec(vec: Vec<Id<Self::Item, Self::Own>>) -> Id<Self> {
let refs = vec.as_refs_slice();
let refs: Vec<&Self::Item> = vec.iter().map(|obj| &**obj).collect();
unsafe {
INSArray::from_refs(refs)
INSArray::from_refs(&refs)
}
}

Expand Down Expand Up @@ -143,9 +143,9 @@ pub trait INSSharedArray : INSArray<Own=Shared> {
}

fn from_slice(slice: &[ShareId<Self::Item>]) -> Id<Self> {
let refs = slice.as_refs_slice();
let refs: Vec<&Self::Item> = slice.iter().map(|obj| &**obj).collect();
unsafe {
INSArray::from_refs(refs)
INSArray::from_refs(&refs)
}
}

Expand Down
6 changes: 3 additions & 3 deletions foundation/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;
use std::ops::Index;
use std::ptr;

use objc::{Id, IdSlice, Owned, Ownership, ShareId};
use objc::{Id, Owned, Ownership, ShareId};
use objc::runtime::Class;

use {
Expand Down Expand Up @@ -99,9 +99,9 @@ pub trait INSDictionary : INSObject {
fn from_keys_and_objects<T>(keys: &[&T],
vals: Vec<Id<Self::Value, Self::Own>>) -> Id<Self>
where T: INSCopying<Output=Self::Key> {
let vals_refs = vals.as_refs_slice();
let vals_refs: Vec<&Self::Value> = vals.iter().map(|obj| &**obj).collect();
unsafe {
INSDictionary::from_refs(keys, vals_refs)
INSDictionary::from_refs(keys, &vals_refs)
}
}

Expand Down

0 comments on commit 4118e96

Please sign in to comment.