Skip to main content

collect_list

Function collect_list 

Source
pub unsafe fn collect_list<'a, I, T>(
    scope: &'a ProtectScope,
    iter: I,
) -> Root<'a>
where I: IntoIterator<Item = T>, T: IntoR,
Expand description

Collect an iterator into an R list with bounded protect stack usage.

This is a convenience wrapper around ListAccumulator for iterator-based collection. Each element is converted via IntoR.

§Safety

Must be called from the R main thread.

§Example

unsafe fn squares(n: usize) -> SEXP {
    let scope = ProtectScope::new();
    collect_list(&scope, (0..n).map(|i| (i * i) as i32)).get()
}