pub struct JsMetadataValue { /* private fields */ }Expand description
JavaScript-friendly metadata value representation.
This type bridges Rust’s MetadataValue enum to JavaScript objects.
Use the static factory methods (fromString, fromInteger, etc.) to create
values from JavaScript.
§Example (JavaScript)
const strValue = JsMetadataValue.fromString('hello');
const intValue = JsMetadataValue.fromInteger(42);
const floatValue = JsMetadataValue.fromFloat(3.14);
const boolValue = JsMetadataValue.fromBoolean(true);
const arrValue = JsMetadataValue.fromStringArray(['a', 'b', 'c']);
console.log(strValue.getType()); // 'string'
console.log(intValue.toJS()); // 42Implementations§
Source§impl JsMetadataValue
impl JsMetadataValue
Sourcepub fn from_string(value: String) -> Self
pub fn from_string(value: String) -> Self
Creates a string metadata value.
@param value - The string value @returns A new JsMetadataValue containing a string
Sourcepub fn from_integer(value: f64) -> Result<Self, JsError>
pub fn from_integer(value: f64) -> Result<Self, JsError>
Creates an integer metadata value.
JavaScript numbers are always f64, so this method validates the input to ensure it’s a valid integer within JavaScript’s safe integer range.
@param value - The integer value (must be within ±(2^53 - 1)) @returns A new JsMetadataValue containing an integer @throws {Error} If value is outside safe integer range or has fractional part
§Errors
Returns an error if:
- Value exceeds JavaScript’s safe integer range (±9007199254740991)
- Value has a fractional part (e.g., 3.14)
- Value is NaN or Infinity
Sourcepub fn from_float(value: f64) -> Self
pub fn from_float(value: f64) -> Self
Creates a float metadata value.
@param value - The float value (must not be NaN or Infinity) @returns A new JsMetadataValue containing a float
Sourcepub fn from_boolean(value: bool) -> Self
pub fn from_boolean(value: bool) -> Self
Creates a boolean metadata value.
@param value - The boolean value @returns A new JsMetadataValue containing a boolean
Sourcepub fn from_string_array(value: Array) -> Result<Self, JsError>
pub fn from_string_array(value: Array) -> Result<Self, JsError>
Creates a string array metadata value.
@param value - An array of strings @returns A new JsMetadataValue containing a string array
§Errors
Returns an error if any array element is not a string.
Sourcepub fn get_type(&self) -> String
pub fn get_type(&self) -> String
Returns the type of this value.
@returns One of: ‘string’, ‘integer’, ‘float’, ‘boolean’, ‘string_array’
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Checks if this value is an integer.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Checks if this value is a boolean.
Sourcepub fn is_string_array(&self) -> bool
pub fn is_string_array(&self) -> bool
Checks if this value is a string array.
Sourcepub fn as_string(&self) -> Option<String>
pub fn as_string(&self) -> Option<String>
Gets the value as a string.
@returns The string value, or undefined if not a string
Sourcepub fn as_integer(&self) -> Option<f64>
pub fn as_integer(&self) -> Option<f64>
Gets the value as an integer.
Note: Returns as f64 for JavaScript compatibility. Safe for integers up to ±2^53.
@returns The integer value as a number, or undefined if not an integer
Sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Gets the value as a float.
@returns The float value, or undefined if not a float
Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Gets the value as a boolean.
@returns The boolean value, or undefined if not a boolean
Sourcepub fn as_string_array(&self) -> JsValue
pub fn as_string_array(&self) -> JsValue
Gets the value as a string array.
@returns The string array, or undefined if not a string array
Trait Implementations§
Source§impl From<JsMetadataValue> for JsValue
impl From<JsMetadataValue> for JsValue
Source§fn from(value: JsMetadataValue) -> Self
fn from(value: JsMetadataValue) -> Self
Source§impl FromWasmAbi for JsMetadataValue
impl FromWasmAbi for JsMetadataValue
Source§impl IntoWasmAbi for JsMetadataValue
impl IntoWasmAbi for JsMetadataValue
Source§impl LongRefFromWasmAbi for JsMetadataValue
impl LongRefFromWasmAbi for JsMetadataValue
Source§impl OptionFromWasmAbi for JsMetadataValue
impl OptionFromWasmAbi for JsMetadataValue
Source§impl OptionIntoWasmAbi for JsMetadataValue
impl OptionIntoWasmAbi for JsMetadataValue
Source§impl RefFromWasmAbi for JsMetadataValue
impl RefFromWasmAbi for JsMetadataValue
Source§type Anchor = RcRef<JsMetadataValue>
type Anchor = RcRef<JsMetadataValue>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for JsMetadataValue
impl RefMutFromWasmAbi for JsMetadataValue
Source§impl TryFromJsValue for JsMetadataValue
impl TryFromJsValue for JsMetadataValue
Source§impl VectorFromWasmAbi for JsMetadataValue
impl VectorFromWasmAbi for JsMetadataValue
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[JsMetadataValue]>
Source§impl VectorIntoWasmAbi for JsMetadataValue
impl VectorIntoWasmAbi for JsMetadataValue
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[JsMetadataValue]>) -> Self::Abi
Source§impl WasmDescribeVector for JsMetadataValue
impl WasmDescribeVector for JsMetadataValue
impl SupportsConstructor for JsMetadataValue
impl SupportsInstanceProperty for JsMetadataValue
impl SupportsStaticProperty for JsMetadataValue
Auto Trait Implementations§
impl Freeze for JsMetadataValue
impl RefUnwindSafe for JsMetadataValue
impl Send for JsMetadataValue
impl Sync for JsMetadataValue
impl Unpin for JsMetadataValue
impl UnwindSafe for JsMetadataValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.