Struct starlark::environment::GlobalsStatic
source · [−]pub struct GlobalsStatic(_);
Expand description
Used to create methods for a StarlarkValue
.
To define a method foo()
on your type, define
usually written as:
ⓘ
fn my_methods(builder: &mut GlobalsBuilder) {
fn foo(me: ARef<Foo>) -> anyhow::Result<NoneType> {
...
}
}
impl StarlarkValue<'_> for Foo {
...
fn get_methods(&self) -> Option<&'static Globals> {
static RES: GlobalsStatic = GlobalsStatic::new();
RES.methods(module_creator)
}
...
}
Implementations
sourceimpl GlobalsStatic
impl GlobalsStatic
sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new GlobalsStatic
.
sourcepub fn function(
&'static self,
x: impl FnOnce(&mut GlobalsBuilder)
) -> FrozenValue
pub fn function(
&'static self,
x: impl FnOnce(&mut GlobalsBuilder)
) -> FrozenValue
Get a function out of the object. Requires that the function passed only set a single
value. If populated via a #[starlark_module]
, that means a single function in it.
sourcepub fn populate(
&'static self,
x: impl FnOnce(&mut GlobalsBuilder),
out: &mut GlobalsBuilder
)
pub fn populate(
&'static self,
x: impl FnOnce(&mut GlobalsBuilder),
out: &mut GlobalsBuilder
)
Move all the globals in this GlobalsBuilder
into a new one. All variables will
only be allocated once (ensuring things like function comparison works properly).
Auto Trait Implementations
impl !RefUnwindSafe for GlobalsStatic
impl Send for GlobalsStatic
impl Sync for GlobalsStatic
impl Unpin for GlobalsStatic
impl !UnwindSafe for GlobalsStatic
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