add tests and expose types

This commit is contained in:
Brendan Hansknecht 2022-10-18 23:35:15 -07:00
parent 58f4afd9f0
commit 24cd78fe7e
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
4 changed files with 98 additions and 5 deletions

View file

@ -19,9 +19,9 @@ mod storage;
pub use roc_box::RocBox;
pub use roc_dict::RocDict;
pub use roc_list::RocList;
pub use roc_list::{RocList, SendSafeRocList};
pub use roc_set::RocSet;
pub use roc_str::{InteriorNulError, RocStr};
pub use roc_str::{InteriorNulError, RocStr, SendSafeRocStr};
pub use storage::Storage;
// A list of C functions that are being imported

View file

@ -121,6 +121,15 @@ impl<T> RocList<T> {
}
}
// Marks a list as readonly. This means that it will be leaked.
// For constants passed in from platform to application, this may be reasonable.
// Marked unsafe because it should not be used lightly.
pub unsafe fn set_readonly(&self) {
if let Some((_, storage)) = self.elements_and_storage() {
storage.set(Storage::Readonly);
}
}
/// Note that there is no way to convert directly to a Vec.
///
/// This is because RocList values are not allocated using the system allocator, so

View file

@ -123,6 +123,16 @@ impl RocStr {
}
}
// Marks a str as readonly. This means that it will be leaked.
// For constants passed in from platform to application, this may be reasonable.
// Marked unsafe because it should not be used lightly.
pub unsafe fn set_readonly(&self) {
match self.as_enum_ref() {
RocStrInnerRef::HeapAllocated(roc_list) => unsafe { roc_list.set_readonly() },
RocStrInnerRef::SmallString(_) => {}
}
}
/// Note that there is no way to convert directly to a String.
///
/// This is because RocStr values are not allocated using the system allocator, so