[−][src]Struct boa::builtins::object::InternalStateCell
Wrapper around Rc
to implement Trace
and Finalize
.
Methods
impl InternalStateCell
[src]
pub fn new<T: Any + InternalState>(value: T) -> Self
[src]
Create new InternalStateCell
from a value.
pub fn downcast_ref<T: Any + InternalState>(&self) -> Option<&T>
[src]
Get a reference to the stored value and cast it to T
.
pub fn downcast_mut<T: Any + InternalState>(&mut self) -> Option<&mut T>
[src]
Get a mutable reference to the stored value and cast it to T
.
Methods from Deref<Target = dyn Any>
pub fn is<T>(&self) -> bool where
T: Any,
1.0.0[src]
T: Any,
Returns true
if the boxed type is the same as T
.
Examples
use std::any::Any; fn is_string(s: &dyn Any) { if s.is::<String>() { println!("It's a string!"); } else { println!("Not a string..."); } } is_string(&0); is_string(&"cookie monster".to_string());
pub fn downcast_ref<T>(&self) -> Option<&T> where
T: Any,
1.0.0[src]
T: Any,
Returns some reference to the boxed value if it is of type T
, or
None
if it isn't.
Examples
use std::any::Any; fn print_if_string(s: &dyn Any) { if let Some(string) = s.downcast_ref::<String>() { println!("It's a string({}): '{}'", string.len(), string); } else { println!("Not a string..."); } } print_if_string(&0); print_if_string(&"cookie monster".to_string());
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
1.0.0[src]
T: Any,
Returns some mutable reference to the boxed value if it is of type T
, or
None
if it isn't.
Examples
use std::any::Any; fn modify_if_u32(s: &mut dyn Any) { if let Some(num) = s.downcast_mut::<u32>() { *num = 42; } } let mut x = 10u32; let mut s = "starlord".to_string(); modify_if_u32(&mut x); modify_if_u32(&mut s); assert_eq!(x, 42); assert_eq!(&s, "starlord");
pub fn is<T>(&self) -> bool where
T: Any,
1.0.0[src]
T: Any,
Forwards to the method defined on the type Any
.
Examples
use std::any::Any; fn is_string(s: &(dyn Any + Send)) { if s.is::<String>() { println!("It's a string!"); } else { println!("Not a string..."); } } is_string(&0); is_string(&"cookie monster".to_string());
pub fn downcast_ref<T>(&self) -> Option<&T> where
T: Any,
1.0.0[src]
T: Any,
Forwards to the method defined on the type Any
.
Examples
use std::any::Any; fn print_if_string(s: &(dyn Any + Send)) { if let Some(string) = s.downcast_ref::<String>() { println!("It's a string({}): '{}'", string.len(), string); } else { println!("Not a string..."); } } print_if_string(&0); print_if_string(&"cookie monster".to_string());
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
1.0.0[src]
T: Any,
Forwards to the method defined on the type Any
.
Examples
use std::any::Any; fn modify_if_u32(s: &mut (dyn Any + Send)) { if let Some(num) = s.downcast_mut::<u32>() { *num = 42; } } let mut x = 10u32; let mut s = "starlord".to_string(); modify_if_u32(&mut x); modify_if_u32(&mut s); assert_eq!(x, 42); assert_eq!(&s, "starlord");
pub fn is<T>(&self) -> bool where
T: Any,
1.28.0[src]
T: Any,
Forwards to the method defined on the type Any
.
Examples
use std::any::Any; fn is_string(s: &(dyn Any + Send + Sync)) { if s.is::<String>() { println!("It's a string!"); } else { println!("Not a string..."); } } is_string(&0); is_string(&"cookie monster".to_string());
pub fn downcast_ref<T>(&self) -> Option<&T> where
T: Any,
1.28.0[src]
T: Any,
Forwards to the method defined on the type Any
.
Examples
use std::any::Any; fn print_if_string(s: &(dyn Any + Send + Sync)) { if let Some(string) = s.downcast_ref::<String>() { println!("It's a string({}): '{}'", string.len(), string); } else { println!("Not a string..."); } } print_if_string(&0); print_if_string(&"cookie monster".to_string());
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
1.28.0[src]
T: Any,
Forwards to the method defined on the type Any
.
Examples
use std::any::Any; fn modify_if_u32(s: &mut (dyn Any + Send + Sync)) { if let Some(num) = s.downcast_mut::<u32>() { *num = 42; } } let mut x = 10u32; let mut s = "starlord".to_string(); modify_if_u32(&mut x); modify_if_u32(&mut s); assert_eq!(x, 42); assert_eq!(&s, "starlord");
Trait Implementations
impl Clone for InternalStateCell
[src]
fn clone(&self) -> InternalStateCell
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for InternalStateCell
[src]
The derived version would print 'InternalStateCell { state: ... }', this custom implementation only prints the actual internal state.
impl Deref for InternalStateCell
[src]
impl DerefMut for InternalStateCell
[src]
impl Finalize for InternalStateCell
[src]
impl Trace for InternalStateCell
[src]
Auto Trait Implementations
impl !RefUnwindSafe for InternalStateCell
impl !Send for InternalStateCell
impl !Sync for InternalStateCell
impl Unpin for InternalStateCell
impl !UnwindSafe for InternalStateCell
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,