Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string: add impl From<&IString> for IString #37

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ impl<T: ImplicitClone + 'static> From<Rc<[T]>> for IArray<T> {
}
}

impl<T: ImplicitClone + 'static> From<&IArray<T>> for IArray<T> {
fn from(a: &IArray<T>) -> IArray<T> {
a.clone()
}
}

impl<T: ImplicitClone + 'static> IArray<T> {
/// Returns an iterator over the slice.
///
Expand Down Expand Up @@ -356,4 +362,10 @@ mod test_array {
const _ARRAY_F32: IArray<f32> = IArray::Static(&[]);
const _ARRAY_F64: IArray<f64> = IArray::Static(&[]);
}

#[test]
fn from() {
let x: IArray<u32> = IArray::Static(&[]);
let _out = IArray::from(&x);
}
}
14 changes: 14 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'sta
}
}

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static>
From<&IMap<K, V>> for IMap<K, V>
{
fn from(a: &IMap<K, V>) -> IMap<K, V> {
a.clone()
}
}

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> IMap<K, V> {
/// Return an iterator over the key-value pairs of the map, in their order.
#[inline]
Expand Down Expand Up @@ -425,4 +433,10 @@ mod test_map {
const _MAP_F32: IMap<u32, f32> = IMap::Static(&[]);
const _MAP_F64: IMap<u32, f64> = IMap::Static(&[]);
}

#[test]
fn from() {
let x: IMap<u32, u32> = IMap::Static(&[]);
let _out = IMap::from(&x);
}
}
12 changes: 12 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ impl From<Cow<'static, str>> for IString {
}
}

impl From<&IString> for IString {
fn from(s: &IString) -> IString {
s.clone()
}
}

macro_rules! impl_cmp_as_str {
(PartialEq::<$type1:ty, $type2:ty>) => {
impl_cmp_as_str!(PartialEq::<$type1, $type2>::eq -> bool);
Expand Down Expand Up @@ -394,4 +400,10 @@ mod test_string {
// this assert exists to ensure the cow lives after the strong_count assert
assert_eq!(cow, "foo");
}

#[test]
fn from_ref() {
let s = IString::Static("foo");
let _out = IString::from(&s);
}
}
Loading