Merge remote-tracking branch 'origin/main' into glue-getters-rtfeldman

This commit is contained in:
Folkert 2023-03-08 19:46:00 +01:00
commit fe15a2e79c
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
124 changed files with 2445 additions and 9925 deletions

View file

@ -46,7 +46,14 @@ impl<K, V> RocDict<K, V> {
}
impl<K: Hash, V> RocDict<K, V> {
pub fn from_iter<I: Iterator<Item = (K, V)>>(src: I) -> Self {
unsafe fn insert_unchecked(&mut self, _key: K, _val: V) {
todo!();
}
}
impl<K: Hash, V> FromIterator<(K, V)> for RocDict<K, V> {
fn from_iter<T: IntoIterator<Item = (K, V)>>(into_iter: T) -> Self {
let src = into_iter.into_iter();
let mut ret = Self::with_capacity(src.size_hint().0);
for (key, val) in src {
@ -57,16 +64,6 @@ impl<K: Hash, V> RocDict<K, V> {
ret
}
unsafe fn insert_unchecked(&mut self, _key: K, _val: V) {
todo!();
}
}
impl<'a, K: Hash, V> FromIterator<(K, V)> for RocDict<K, V> {
fn from_iter<T: IntoIterator<Item = (K, V)>>(into_iter: T) -> Self {
RocDict::from_iter(into_iter.into_iter())
}
}
impl<'a, K, V> IntoIterator for &'a RocDict<K, V> {

View file

@ -159,7 +159,7 @@ impl<T> RocList<T> {
/// bytes over - in other words, calling this `as_slice` method and then calling `to_vec`
/// on that.
pub fn as_slice(&self) -> &[T] {
&*self
self
}
/// Note that there is no way to convert directly to a Vec.

View file

@ -5,12 +5,7 @@ use core::{
};
#[derive(Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
struct Unit;
#[derive(Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct RocSet<T>(RocDict<T, Unit>);
pub struct RocSet<T>(RocDict<T, ()>);
impl<T> RocSet<T> {
pub fn len(&self) -> usize {
@ -32,10 +27,11 @@ impl<T> RocSet<T> {
}
}
impl<T: Hash> RocSet<T> {
#[allow(unused)]
pub fn from_iter<I: Iterator<Item = T>>(src: I) -> Self {
Self(RocDict::from_iter(src.map(|elem| (elem, Unit))))
impl<T: Hash> FromIterator<T> for RocSet<T> {
fn from_iter<I: IntoIterator<Item = T>>(into_iter: I) -> Self {
Self(RocDict::from_iter(
into_iter.into_iter().map(|elem| (elem, ())),
))
}
}

View file

@ -154,7 +154,7 @@ impl RocStr {
/// bytes over - in other words, calling this `as_str` method and then calling `to_string`
/// on that.
pub fn as_str(&self) -> &str {
&*self
self
}
/// Create an empty RocStr with enough space preallocated to store
@ -562,8 +562,8 @@ impl Deref for RocStr {
fn deref(&self) -> &Self::Target {
match self.as_enum_ref() {
RocStrInnerRef::HeapAllocated(h) => unsafe { core::str::from_utf8_unchecked(&*h) },
RocStrInnerRef::SmallString(s) => &*s,
RocStrInnerRef::HeapAllocated(h) => unsafe { core::str::from_utf8_unchecked(h) },
RocStrInnerRef::SmallString(s) => s,
}
}
}