Struct starlark::environment::GlobalsBuilder
source · [−]pub struct GlobalsBuilder { /* private fields */ }
Expand description
Used to build a Globals
value.
Implementations
sourceimpl 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() -> Self
pub fn extended() -> Self
Create a GlobalsBuilder
combining those functions in the Starlark standard plus
all those defined in LibraryExtension
.
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 Fn(&mut GlobalsBuilder))
pub fn struct_(&mut self, name: &str, f: impl Fn(&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
.
This function cannot be called recursively from inside f
.
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,
typ: Option<FrozenValue>,
f: F
) where
F: for<'v> Fn(&mut Evaluator<'v, '_>, &Arguments<'v, '_>) -> Result<Value<'v>> + Send + Sync + 'static,
pub fn set_function<F>(
&mut self,
name: &str,
speculative_exec_safe: bool,
raw_docs: NativeCallableRawDocs,
typ: Option<FrozenValue>,
f: F
) where
F: for<'v> Fn(&mut Evaluator<'v, '_>, &Arguments<'v, '_>) -> Result<Value<'v>> + Send + Sync + 'static,
Set a method. This function is usually called from code
generated by starlark_derive
and rarely needs to be called manually.
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.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for GlobalsBuilder
impl Send for GlobalsBuilder
impl !Sync for GlobalsBuilder
impl Unpin for GlobalsBuilder
impl !UnwindSafe for GlobalsBuilder
Blanket Implementations
sourceimpl<T> AsARef<T> for T where
T: ?Sized,
impl<T> AsARef<T> for T where
T: ?Sized,
sourcefn try_as_aref(this: &T) -> Result<ARef<'_, T>, BorrowError>
fn try_as_aref(this: &T) -> Result<ARef<'_, T>, BorrowError>
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more