ron_wasm/stringify.rs
1// SPDX-FileCopyrightText: 2024 Shun Sakai
2//
3// SPDX-License-Identifier: Apache-2.0 OR MIT
4
5//! Converts the JavaScript value to the RON string.
6
7use ron::Value;
8use wasm_bindgen::{JsError, JsValue, prelude::wasm_bindgen};
9
10/// Converts a JavaScript value to a RON string.
11///
12/// # Errors
13///
14/// Returns an error if any of the following are true:
15///
16/// - Cannot convert `value` to a RON value.
17/// - Cannot convert a RON value to a RON string.
18#[wasm_bindgen]
19pub fn stringify(value: JsValue) -> Result<String, JsError> {
20 let value: Value = serde_wasm_bindgen::from_value(value)?;
21 ron::to_string(&value).map_err(JsError::from)
22}