Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Undefined,
    Null,
    Bool(bool),
    Number(f64),
    Str(Rc<String>),
    BigInt(Rc<BigInt>),
    Object(ObjRef),
}
Expand description

JS の値。プリミティブ + オブジェクト参照。

Variants§

§

Undefined

§

Null

§

Bool(bool)

§

Number(f64)

§

Str(Rc<String>)

§

BigInt(Rc<BigInt>)

任意精度整数 BigInt。

§

Object(ObjRef)

Implementations§

Source§

impl Value

Source

pub fn str(s: impl Into<String>) -> Value

Source

pub fn bigint(b: BigInt) -> Value

Source

pub fn object(o: ObjRef) -> Value

Source

pub fn truthy(&self) -> bool

ECMAScript ToBoolean。

Source

pub fn to_number(&self) -> f64

ECMAScript ToNumber(簡易)。

Source

pub fn type_of(&self) -> &'static str

型を表す typeof 文字列。

Source

pub fn to_js_string(&self) -> String

ECMAScript ToString(簡易・表示用)。

Source

fn to_js_string_seen(&self, seen: &mut Vec<ObjRef>) -> String

to_js_string の内部実装。Array の要素文字列化は再帰的に自分自身の to_js_string を呼ぶため、var a=[1]; a.push(a); a.join()(あるいは String(a)/テンプレートリテラル補間等、内部的に同じ経路を通る操作)が 循環参照でスタックオーバーフロー(この no_std 環境ではクラッシュ/ハングに なり得る)していた。structuredClone/JSON.stringify/console.log で 既に修正済みの「祖先を追跡して打ち切る」パターンをここにも適用し、 既に祖先に現れた配列を再訪した時点で空文字列を返して打ち切る (実ブラウザは無条件のスタックオーバーフローで RangeError を投げるが、 この処理系は例外化されない Rust ネイティブ再帰でのクラッシュを避ける ことを優先し、値としては空文字列で打ち切る簡略挙動とする。 a=[1]; a.push(a); a.join()"1,1," になる——2番目の要素 a 自身の to_js_string() が、その内部で自分自身を再訪した時点(3階層目)で 空文字列に切り詰められるため)。

Source

pub fn strict_eq(&self, other: &Value) -> bool

=== 厳密等価。

Source

pub fn same_ref(&self, other: &Value) -> bool

同一オブジェクト参照か(関数リスナの照合用)。プリミティブは strict_eq に委譲。

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl !UnwindSafe for Value

§

impl Freeze for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

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> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.