Struct starlark::environment::GlobalsBuilder
source · pub struct GlobalsBuilder { /* private fields */ }
Expand description
Used to build a Globals
value.
Implementations§
source§impl GlobalsBuilder
impl GlobalsBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty GlobalsBuilder
, with no functions in scope.
sourcepub fn standard() -> Self
pub fn standard() -> Self
Create a GlobalsBuilder
following the
Starlark standard.
sourcepub fn extended_by(extensions: &[LibraryExtension]) -> Self
pub fn extended_by(extensions: &[LibraryExtension]) -> Self
Create a GlobalsBuilder
combining those functions in the Starlark standard plus
all those defined in LibraryExtension
.
sourcepub fn struct_(&mut self, name: &str, f: impl FnOnce(&mut GlobalsBuilder))
pub fn struct_(&mut self, name: &str, f: impl FnOnce(&mut GlobalsBuilder))
Add a nested struct to the builder. If f
adds the definition foo
,
it will end up on a struct name
, accessible as name.foo
.
sourcepub fn with(self, f: impl FnOnce(&mut Self)) -> Self
pub fn with(self, f: impl FnOnce(&mut Self)) -> Self
A fluent API for modifying GlobalsBuilder
and returning the result.
sourcepub fn with_struct(self, name: &str, f: impl Fn(&mut GlobalsBuilder)) -> Self
pub fn with_struct(self, name: &str, f: impl Fn(&mut GlobalsBuilder)) -> Self
A fluent API for modifying GlobalsBuilder
using struct_
.
sourcepub fn set<'v, V: AllocFrozenValue>(&'v mut self, name: &str, value: V)
pub fn set<'v, V: AllocFrozenValue>(&'v mut self, name: &str, value: V)
Set a value in the GlobalsBuilder
.
sourcepub fn set_function<F>(
&mut self,
name: &str,
speculative_exec_safe: bool,
raw_docs: NativeCallableRawDocs,
type_attr: Option<Ty>,
ty: Option<Ty>,
special_builtin_function: Option<SpecialBuiltinFunction>,
f: F
)where
F: NativeFunc,
pub fn set_function<F>(
&mut self,
name: &str,
speculative_exec_safe: bool,
raw_docs: NativeCallableRawDocs,
type_attr: Option<Ty>,
ty: Option<Ty>,
special_builtin_function: Option<SpecialBuiltinFunction>,
f: F
)where
F: NativeFunc,
Set a method. This function is usually called from code
generated by starlark_derive
and rarely needs to be called manually.
sourcepub fn frozen_heap(&self) -> &FrozenHeap
pub fn frozen_heap(&self) -> &FrozenHeap
Heap where globals are allocated. Can be used to allocate additional values.
sourcepub fn alloc<'v, V: AllocFrozenValue>(&'v self, value: V) -> FrozenValue
pub fn alloc<'v, V: AllocFrozenValue>(&'v self, value: V) -> FrozenValue
Allocate a value using the same underlying heap as the GlobalsBuilder
,
only intended for values that are referred to by those which are passed
to set
.
sourcepub fn set_docstring(&mut self, docstring: &str)
pub fn set_docstring(&mut self, docstring: &str)
Set per module docstring.
This function is called by the starlark_derive
generated code
and rarely needs to be called manually.