Skip to content

Commit 3265023

Browse files
committed
refactor: Simplify
1 parent b710e87 commit 3265023

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

src/types/array.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,31 +2951,20 @@ impl From<JanetTuple> for JanetArray {
29512951
}
29522952
}
29532953

2954-
impl TryFrom<&[Janet]> for JanetArray {
2955-
type Error = core::num::TryFromIntError;
2956-
2957-
#[cfg_attr(feature = "inline-more", inline)]
2958-
fn try_from(slice: &[Janet]) -> Result<Self, Self::Error> {
2959-
let len: i32 = slice.len().try_into()?;
2960-
let mut j_array = Self::with_capacity(len as usize);
2961-
2954+
impl From<&[Janet]> for JanetArray {
2955+
fn from(slice: &[Janet]) -> Self {
2956+
let mut j_array = Self::with_capacity(slice.len());
29622957
slice.iter().for_each(|&e| j_array.push(e));
2963-
2964-
Ok(j_array)
2958+
j_array
29652959
}
29662960
}
29672961

2968-
impl TryFrom<&[CJanet]> for JanetArray {
2969-
type Error = core::num::TryFromIntError;
2970-
2971-
#[inline]
2972-
fn try_from(slice: &[CJanet]) -> Result<Self, Self::Error> {
2973-
let len = slice.len().try_into()?;
2974-
2975-
Ok(Self {
2976-
raw: unsafe { evil_janet::janet_array_n(slice.as_ptr(), len) },
2962+
impl From<&[CJanet]> for JanetArray {
2963+
fn from(slice: &[CJanet]) -> Self {
2964+
Self {
2965+
raw: unsafe { evil_janet::janet_array_n(slice.as_ptr(), slice.len() as _) },
29772966
phantom: PhantomData,
2978-
})
2967+
}
29792968
}
29802969
}
29812970

src/types/function.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,12 @@ impl JanetFunction {
185185
///
186186
/// If the executions was successful returns the output, otherwise return the
187187
/// [`CallError`] with information returned by the call.
188+
///
189+
/// # Safety
190+
/// This function may trigger a garbage collection. Any unrooted value created from
191+
/// Rust side must be rooted or dropped before calling this function
188192
#[cfg_attr(feature = "inline-more", inline)]
189-
pub fn call(&mut self, args: impl AsRef<[Janet]>) -> Result<Janet, CallError> {
193+
pub unsafe fn call(&mut self, args: impl AsRef<[Janet]>) -> Result<Janet, CallError> {
190194
let args = args.as_ref();
191195
let mut out = Janet::nil();
192196
let fiber = ptr::null_mut();
@@ -229,7 +233,7 @@ impl JanetFunction {
229233
/// If the executions was successful returns the output, otherwise return the
230234
/// [`CallError`] with information returned by the call.
231235
#[cfg_attr(feature = "inline-more", inline)]
232-
pub fn call_with_fiber(
236+
pub unsafe fn call_with_fiber(
233237
&mut self, mut fiber: JanetFiber, args: impl AsRef<[Janet]>,
234238
) -> Result<Janet, CallError> {
235239
let args = args.as_ref();

0 commit comments

Comments
 (0)