Type Alias Any

Source
pub type Any<D> = OptionalRef<AnyInternal<D>>;

Aliased Type§

pub struct Any<D> { /* private fields */ }

Implementations§

Source§

impl<D: Dealloc> Any<D>

Source

pub fn is<T: AnyCast<D>>(&self) -> bool

Source

pub fn move_from<T: AnyCast<D>>(t: T) -> Self

T should have the same allocator as Any.

use nanvm_lib::{js::{any::Any, js_string::JsStringRef}, mem::{manager::Dealloc, ref_::Ref}};
fn dummy<A: Dealloc>(s: JsStringRef<A>) -> Any<A> {
    Any::move_from(s)
}
use nanvm_lib::{js::{any::Any, js_string::JsStringRef}, mem::{manager::Dealloc, ref_::Ref}};
fn dummy<A: Dealloc, B: Dealloc>(s: JsStringRef<A>) -> Any<B> {
    Any::move_from(s)
}
Source

pub fn try_move<T: AnyCast<D>>(self) -> Result<T, ()>

Source

pub fn get_type(&self) -> Type

Source

pub fn try_ref<T: RefCast<D>>(&self) -> Result<&Block<T, D>, ()>

T should have the same allocator as Any.

use nanvm_lib::{js::{any::Any, js_string::JsStringRef}, mem::{manager::Dealloc, ref_::Ref}};
fn dummy<A: Dealloc>(a: Any<A>) -> JsStringRef<A> {
    a.try_move().unwrap()
}
use nanvm_lib::{js::{any::Any, js_string::JsStringRef}, mem::{manager::Dealloc, ref_::Ref}};
fn dummy<A: Dealloc, B: Dealloc>(a: Any<A>) -> JsStringRef, B> {
    a.try_move().unwrap()
}
Source

pub fn for_each<E>( &self, f: impl FnMut(Any<D>, &Any<D>) -> Result<(), E>, ) -> Result<(), E>

Iterate trough children of this Any. Any type other than array / object yields nothing. For an object, first argument of f is the key string. For an array, it is the index.