Skip to main content

JsSymbol

Struct JsSymbol 

Source
pub struct JsSymbol { /* private fields */ }
Expand description

A JavaScript symbol, stored on the GC heap.

A symbol is a unique property key that is not a string. Its identity is the allocation, not the description: Symbol("a") !== Symbol("a"), and two symbols with the same description still key two different properties. Only Symbol.for produces the same symbol twice, and it does so by looking the key up in the realm’s registry rather than by comparing descriptions.

Implementations§

Source§

impl JsSymbol

Source

pub fn new(description: Option<String>) -> JsSymbol

A unique symbol with description.

Source

pub fn new_private(name: &str) -> JsSymbol

A private symbol: the key of a class’s #name property.

JS_NewSymbolFromAtom(ctx, atom, JS_ATOM_TYPE_PRIVATE), where the atom is the property name including its # — JS_ATOM_hash_constructor is the string "#constructor", which is how the reference rejects that name. The description is therefore #x, and every message that prints this symbol gets the # for free.

Source

pub fn is_private(&self) -> bool

Whether this symbol is a class-private name.

Source

pub fn registered(key: String) -> JsSymbol

The registry entry for key, as Symbol.for returns it.

Source

pub fn identity(&self) -> usize

The description, if there is one. A stable number for this symbol’s identity, for hashing.

A symbol’s identity is its allocation — Symbol("a") and Symbol("a") are two different keys — so the address is the right hash, and it is only ever hashed.

Source

pub fn description(&self) -> Option<&str>

The description shown by Symbol.prototype.description and toString.

Source

pub fn registry_key(&self) -> Option<&str>

The registry key, if this symbol came from Symbol.for.

Source

pub fn to_display_string(&self) -> String

Symbol.prototype.toString: Symbol(description).

A description is inserted verbatim, so Symbol("a)b").toString() is Symbol(a)b) — the spec does not escape it.

Trait Implementations§

Source§

impl Debug for JsSymbol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Trace for JsSymbol

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.
Source§

fn external_bytes(&self) -> usize

Bytes this value owns outside its own box: a string’s buffer, an array’s element vector, a buffer’s bytes. Read more

Auto Trait Implementations§

§

impl Forget for JsSymbol

§

impl Freeze for JsSymbol
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for JsSymbol

§

impl RefUnwindSafe for JsSymbol

§

impl Send for JsSymbol
where RawVecInner: Send,

§

impl Sync for JsSymbol
where RawVecInner: Sync,

§

impl Unpin for JsSymbol
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for JsSymbol

§

impl UnwindSafe for JsSymbol
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.