MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / try_new

Method try_new

aiscript-arena/src/arena.rs:152–162  ·  view source on GitHub ↗

Similar to `new`, but allows for constructor that can fail.

(f: F)

Source from the content-addressed store, hash-verified

150
151 /// Similar to `new`, but allows for constructor that can fail.
152 pub fn try_new<F, E>(f: F) -> Result<Arena<R>, E>
153 where
154 F: for<'gc> FnOnce(&'gc Mutation<'gc>) -> Result<Root<'gc, R>, E>,
155 {
156 unsafe {
157 let context = Box::new(Context::new());
158 let mc: &'static Mutation<'_> = &*(context.mutation_context() as *const _);
159 let root: Root<'static, R> = f(mc)?;
160 Ok(Arena { context, root })
161 }
162 }
163
164 #[inline]
165 pub fn map_root<R2>(

Callers

nothing calls this directly

Calls 1

mutation_contextMethod · 0.80

Tested by

no test coverage detected