MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / new

Method new

aiscript-arena/src/arena.rs:132–149  ·  view source on GitHub ↗

Create a new arena with the given garbage collector tuning parameters. You must provide a closure that accepts a `&Mutation<'gc>` and returns the appropriate root.

(f: F)

Source from the content-addressed store, hash-verified

130 /// Create a new arena with the given garbage collector tuning parameters. You must provide a
131 /// closure that accepts a `&Mutation<'gc>` and returns the appropriate root.
132 pub fn new<F>(f: F) -> Arena<R>
133 where
134 F: for<'gc> FnOnce(&'gc Mutation<'gc>) -> Root<'gc, R>,
135 {
136 unsafe {
137 let context = Box::new(Context::new());
138 // Note - we cast the `&Mutation` to a `'static` lifetime here,
139 // instead of transmuting the root type returned by `f`. Transmuting the root
140 // type is allowed in nightly versions of rust
141 // (see https://github.com/rust-lang/rust/pull/101520#issuecomment-1252016235)
142 // but is not yet stable. Casting the `&Mutation` is completely invisible
143 // to the callback `f` (since it needs to handle an arbitrary lifetime),
144 // and lets us stay compatible with older versions of Rust
145 let mc: &'static Mutation<'_> = &*(context.mutation_context() as *const _);
146 let root: Root<'static, R> = f(mc);
147 Arena { context, root }
148 }
149 }
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>

Callers

nothing calls this directly

Calls 1

mutation_contextMethod · 0.80

Tested by

no test coverage detected