Skip to main content

PropertyKey

Enum PropertyKey 

Source
pub enum PropertyKey {
    String(Wtf8),
    Symbol(Gc<JsSymbol>),
}
Expand description

The mutable half of an object. What a property is keyed by.

A string and a symbol are separate key spaces even when they look alike: o["a"] and o[Symbol("a")] are two properties, and o[Symbol("a")] is not reachable by any string. Symbols are also invisible to for/Object.keys/JSON.stringify, which is the whole point of them, so the distinction has to survive into the property table rather than being flattened into a name.

Variants§

§

String(Wtf8)

An ordinary string key, held as WTF-8 so a key containing an unpaired surrogate addresses one property rather than colliding with its U+FFFD replacement.

§

Symbol(Gc<JsSymbol>)

A symbol key.

Implementations§

Source§

impl PropertyKey

Source

pub fn hash_code(&self) -> usize

A cheap hash of this key, for an inline cache’s slot choice.

Not a hash of the whole string: a long property name would make the cache slower than the lookup it is caching. Mixing the length with the first and last byte is enough to separate the names that appear on one object (x/y, value/add), and a collision only costs a miss.

Source§

impl PropertyKey

Source

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

The key as a string, for the operations that only accept one.

A symbol has no string form that would address it, so this answers None — which is what makes get_field on a symbol key fall through to the general path instead of silently reading a same-named string property.

Source

pub fn as_wtf8(&self) -> Option<&Wtf8>

The key’s bytes, which a string key always has and a symbol never does.

Source

pub fn is_symbol(&self) -> bool

Whether this is an ordinary string key.

Trait Implementations§

Source§

impl Clone for PropertyKey

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Display for PropertyKey

Source§

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

How a key reads inside an error message: strings bare, symbols in their Symbol(description) form.

Source§

impl From<&str> for PropertyKey

Source§

fn from(text: &str) -> PropertyKey

Converts to this type from the input type.
Source§

impl From<String> for PropertyKey

Source§

fn from(text: String) -> PropertyKey

Converts to this type from the input type.
Source§

impl From<Wtf8> for PropertyKey

Source§

fn from(text: Wtf8) -> PropertyKey

Converts to this type from the input type.
Source§

impl PartialEq for PropertyKey

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Trace for PropertyKey

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 !RefUnwindSafe for PropertyKey

§

impl !Send for PropertyKey

§

impl !Sync for PropertyKey

§

impl !UnwindSafe for PropertyKey

§

impl Forget for PropertyKey

§

impl Freeze for PropertyKey
where *const RcInner<[u8]> is !null: Freeze, PhantomData<RcInner<[u8]>>: Freeze, *const GcBox<JsSymbol> is !null: Freeze,

§

impl Move for PropertyKey

§

impl Unpin for PropertyKey
where Rc<[u8]>: Unpin, *const GcBox<JsSymbol> is !null: Unpin,

§

impl UnsafeUnpin for PropertyKey
where *const RcInner<[u8]> is !null: UnsafeUnpin, PhantomData<RcInner<[u8]>>: UnsafeUnpin, *const GcBox<JsSymbol> is !null: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.