diff --git a/Cargo.toml b/Cargo.toml index 70434b28b..5c3b78c4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ resolver = "2" members = [ "rbx_binary", + "rbx_binary_wasm", "rbx_dom_weak", "rbx_reflector", "rbx_reflection", diff --git a/rbx_binary_wasm/.gitignore b/rbx_binary_wasm/.gitignore new file mode 100644 index 000000000..4e301317e --- /dev/null +++ b/rbx_binary_wasm/.gitignore @@ -0,0 +1,6 @@ +/target +**/*.rs.bk +Cargo.lock +bin/ +pkg/ +wasm-pack.log diff --git a/rbx_binary_wasm/Cargo.toml b/rbx_binary_wasm/Cargo.toml new file mode 100644 index 000000000..2ae431986 --- /dev/null +++ b/rbx_binary_wasm/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "rbx-binary" +version = "0.1.0" +edition = "2018" +description = "WebAssembly build of rbx_binary for decoding and encoding binary Roblox files." +repository = "https://github.com/rojo-rbx/rbx-dom" +license = "MIT" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +default = ["console_error_panic_hook"] + +[dependencies] +serde-wasm-bindgen = "0.4" +tsify = "0.4.5" +wasm-bindgen = "0.2.84" + +rbx_dom_weak = { version = "2.9.0", path = "../rbx_dom_weak" } +rbx_binary = { version = "0.7.7", path = "../rbx_binary" } + +getrandom = { version = "0.2", features = ["js"] } +console_error_panic_hook = { version = "0.1.7", optional = true } diff --git a/rbx_binary_wasm/README.md b/rbx_binary_wasm/README.md new file mode 100644 index 000000000..efe2a1ec0 --- /dev/null +++ b/rbx_binary_wasm/README.md @@ -0,0 +1,14 @@ +# rbx_binary_wasm + +🐉 Thar be dragons 🐉 + +## Prereqs +- [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) +- [npm](https://docs.npmjs.com/getting-started) + +## Building +Run `wasm-pack build` + +## Usage +1. In the `pkg` directory run `npm pack` to package to a tarball. +2. `npm i tarball.tgz` in your project diff --git a/rbx_binary_wasm/src/lib.rs b/rbx_binary_wasm/src/lib.rs new file mode 100644 index 000000000..bda333bd1 --- /dev/null +++ b/rbx_binary_wasm/src/lib.rs @@ -0,0 +1,24 @@ +mod utils; + +use rbx_dom_weak::WeakDom; +use utils::set_panic_hook; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn decode_file(binary_file: Vec) -> WeakDom { + set_panic_hook(); + + let dom = rbx_binary::from_reader(&binary_file[..]).expect("Failed to deserialize binary file."); + + dom +} + +#[wasm_bindgen] +pub fn encode_file(dom: WeakDom) -> Vec { + let mut binary_file = Vec::new(); + + rbx_binary::to_writer(&mut binary_file, &dom, &[dom.root_ref()]) + .expect("Failed to serialize from DOM"); + + binary_file +} diff --git a/rbx_binary_wasm/src/utils.rs b/rbx_binary_wasm/src/utils.rs new file mode 100644 index 000000000..b1d7929dc --- /dev/null +++ b/rbx_binary_wasm/src/utils.rs @@ -0,0 +1,10 @@ +pub fn set_panic_hook() { + // When the `console_error_panic_hook` feature is enabled, we can call the + // `set_panic_hook` function at least once during initialization, and then + // we will get better error messages if our code ever panics. + // + // For more details see + // https://github.com/rustwasm/console_error_panic_hook#readme + #[cfg(feature = "console_error_panic_hook")] + console_error_panic_hook::set_once(); +} diff --git a/rbx_dom_weak/Cargo.toml b/rbx_dom_weak/Cargo.toml index e59388ed6..80726e0e7 100644 --- a/rbx_dom_weak/Cargo.toml +++ b/rbx_dom_weak/Cargo.toml @@ -15,5 +15,8 @@ rbx_types = { version = "1.10.0", path = "../rbx_types", features = ["serde"] } serde = "1.0.137" +tsify = "0.4.5" +wasm-bindgen = "0.2.84" + [dev-dependencies] insta = { version = "1.14.1", features = ["yaml"] } diff --git a/rbx_dom_weak/src/dom.rs b/rbx_dom_weak/src/dom.rs index e558790bc..b3223b301 100644 --- a/rbx_dom_weak/src/dom.rs +++ b/rbx_dom_weak/src/dom.rs @@ -1,6 +1,8 @@ use std::collections::{HashMap, HashSet, VecDeque}; use rbx_types::{Ref, UniqueId, Variant}; +use serde::{Deserialize, Serialize}; +use tsify::Tsify; use crate::instance::{Instance, InstanceBuilder}; @@ -11,10 +13,14 @@ use crate::instance::{Instance, InstanceBuilder}; /// /// When constructing instances, you'll want to create [`InstanceBuilder`] /// objects and insert them into the tree. -#[derive(Debug)] +#[derive(Tsify, Debug, Serialize, Deserialize)] +#[tsify(into_wasm_abi, from_wasm_abi)] pub struct WeakDom { instances: HashMap, + + #[tsify(optional)] root_ref: Ref, + unique_ids: HashSet, } diff --git a/rbx_dom_weak/src/instance.rs b/rbx_dom_weak/src/instance.rs index 7871c3c85..ca3bb3f1a 100644 --- a/rbx_dom_weak/src/instance.rs +++ b/rbx_dom_weak/src/instance.rs @@ -1,6 +1,8 @@ use std::collections::HashMap; use rbx_types::{Ref, Variant}; +use serde::{Deserialize, Serialize}; +use tsify::Tsify; /** Represents an instance that can be turned into a new @@ -183,7 +185,7 @@ impl InstanceBuilder { /// /// Operations that could affect other instances contained in the /// [`WeakDom`][crate::WeakDom] cannot be performed on an `Instance` correctly. -#[derive(Debug)] +#[derive(Tsify, Debug, Serialize, Deserialize)] pub struct Instance { pub(crate) referent: Ref, pub(crate) children: Vec, diff --git a/rbx_types/Cargo.toml b/rbx_types/Cargo.toml index 26fe20a29..50aeb5d78 100644 --- a/rbx_types/Cargo.toml +++ b/rbx_types/Cargo.toml @@ -19,6 +19,9 @@ rand = "0.8.5" thiserror = "1.0.31" serde = { version = "1.0.137", features = ["derive"], optional = true } +tsify = "0.4.5" +wasm-bindgen = "0.2.84" + [dev-dependencies] insta = { version = "1.14.1", features = ["yaml"] } bincode = "1.3.3" diff --git a/rbx_types/src/attributes/mod.rs b/rbx_types/src/attributes/mod.rs index 6432f575a..4a4aac62a 100644 --- a/rbx_types/src/attributes/mod.rs +++ b/rbx_types/src/attributes/mod.rs @@ -15,6 +15,8 @@ use std::{ iter::FromIterator, }; +use tsify::Tsify; + use crate::{Error, Variant}; use self::reader::read_attributes; @@ -22,7 +24,7 @@ use self::writer::write_attributes; pub(crate) use self::error::AttributeError; -#[derive(Debug, Default, Clone, PartialEq)] +#[derive(Tsify, Debug, Default, Clone, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), diff --git a/rbx_types/src/axes.rs b/rbx_types/src/axes.rs index e928d0a58..3528bab50 100644 --- a/rbx_types/src/axes.rs +++ b/rbx_types/src/axes.rs @@ -1,8 +1,11 @@ use std::fmt; +use tsify::Tsify; + use crate::lister::Lister; bitflags::bitflags! { + #[derive(Tsify)] struct AxisFlags: u8 { const X = 1; const Y = 2; @@ -14,7 +17,7 @@ bitflags::bitflags! { /// /// ## See Also /// * [Axes on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Axes) -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Tsify, Clone, Copy, PartialEq, Eq)] pub struct Axes { flags: AxisFlags, } diff --git a/rbx_types/src/basic_types.rs b/rbx_types/src/basic_types.rs index 4d6013119..e927d4b97 100644 --- a/rbx_types/src/basic_types.rs +++ b/rbx_types/src/basic_types.rs @@ -1,4 +1,5 @@ use thiserror::Error; +use tsify::Tsify; use crate::Error; @@ -9,7 +10,7 @@ use crate::Error; /// /// A list of all enums and their values are available [on the Roblox Developer /// Hub](https://developer.roblox.com/en-us/api-reference/enum). -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), @@ -34,7 +35,7 @@ impl Enum { /// ## See Also /// * [`Vector2int16`][struct.Vector2int16.html] /// * [Vector2 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Vector2) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct Vector2 { pub x: f32, pub y: f32, @@ -54,7 +55,7 @@ impl Vector2 { /// * [Vector2int16 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Vector2int16) /// /// [Vector2]: struct.Vector2.html -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq, Eq)] pub struct Vector2int16 { pub x: i16, pub y: i16, @@ -71,7 +72,7 @@ impl Vector2int16 { /// ## See Also /// * [`Vector3int16`][struct.Vector3int16.html] /// * [Vector3 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Vector3) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct Vector3 { pub x: f32, pub y: f32, @@ -135,7 +136,7 @@ impl Vector3 { /// * [Vector3int16 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Vector3int16) /// /// [Vector3]: struct.Vector3.html -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq, Eq)] pub struct Vector3int16 { pub x: i16, pub y: i16, @@ -152,7 +153,7 @@ impl Vector3int16 { /// /// ## See Also /// * [CFrame on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/CFrame) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), @@ -174,7 +175,7 @@ impl CFrame { /// Used to represent the `orientation` field of `CFrame` and not a standalone /// type in Roblox. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct Matrix3 { pub x: Vector3, pub y: Vector3, @@ -360,7 +361,7 @@ impl Matrix3 { /// * [`Color3uint8`](struct.Color3uint8.html), which is used instead of /// `Color3` on some types and does not represent HDR colors. /// * [Color3 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Color3) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct Color3 { pub r: f32, pub g: f32, @@ -393,7 +394,7 @@ impl From for Color3 { /// colors. /// /// [BasePart.Color]: https://developer.roblox.com/en-us/api-reference/property/BasePart/Color -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq, Eq)] pub struct Color3uint8 { pub r: u8, pub g: u8, @@ -424,7 +425,7 @@ impl From for Color3uint8 { /// * [Ray on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Ray) /// /// [FindPartOnRay]: https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartOnRay -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), @@ -446,7 +447,7 @@ impl Ray { /// ## See Also /// * [`Region3int16`](struct.Region3int16.html) /// * [Region3 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Region3) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct Region3 { pub min: Vector3, pub max: Vector3, @@ -466,7 +467,7 @@ impl Region3 { /// * [Region3int16 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Region3int16) /// /// [Region3]: struct.Region3.html -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq, Eq)] pub struct Region3int16 { pub min: Vector3int16, pub max: Vector3int16, @@ -482,7 +483,7 @@ impl Region3int16 { /// /// ## See Also /// * [Rect on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Rect) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct Rect { pub min: Vector2, pub max: Vector2, @@ -499,7 +500,7 @@ impl Rect { /// /// ## See Also /// * [UDim on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/UDim) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct UDim { pub scale: f32, pub offset: i32, @@ -516,7 +517,7 @@ impl UDim { /// /// ## See Also /// * [UDim2 on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/UDim2) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct UDim2 { pub x: UDim, pub y: UDim, @@ -532,7 +533,7 @@ impl UDim2 { /// /// ## See Also /// * [NumberRange on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/NumberRange) -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub struct NumberRange { pub min: f32, pub max: f32, @@ -548,7 +549,7 @@ impl NumberRange { /// /// ## See Also /// * [ColorSequence on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/ColorSequence) -#[derive(Debug, Clone, PartialEq)] +#[derive(Tsify, Debug, Clone, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), @@ -564,7 +565,7 @@ pub struct ColorSequence { /// * [ColorSequenceKeypoint on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/ColorSequenceKeypoint) /// /// [ColorSequence]: struct.ColorSequence.html -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), @@ -586,7 +587,7 @@ impl ColorSequenceKeypoint { /// /// ## See Also /// * [NumberSequence on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/NumberSequence) -#[derive(Debug, Clone, PartialEq)] +#[derive(Tsify, Debug, Clone, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), @@ -603,7 +604,7 @@ pub struct NumberSequence { /// * [NumberSequenceKeypoint on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/NumberSequenceKeypoint) /// /// [NumberSequence]: struct.NumberSequence.html -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), diff --git a/rbx_types/src/binary_string.rs b/rbx_types/src/binary_string.rs index d5e7a3acc..e7ac3d9bd 100644 --- a/rbx_types/src/binary_string.rs +++ b/rbx_types/src/binary_string.rs @@ -1,9 +1,11 @@ +use tsify::Tsify; + /// Container for untyped binary data. /// /// `BinaryString` is used in cases where the type of the underlying data is /// unknown or unimplemented. Where possible, stronger types that interpret the /// underlying bytes should be preferred. -#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] +#[derive(Tsify, Debug, Clone, Default, PartialEq, Eq, Hash)] pub struct BinaryString { buffer: Vec, } diff --git a/rbx_types/src/brick_color.rs b/rbx_types/src/brick_color.rs index 2b9b57fd8..8ce010334 100644 --- a/rbx_types/src/brick_color.rs +++ b/rbx_types/src/brick_color.rs @@ -2,6 +2,8 @@ use std::fmt; use crate::Color3uint8; +use tsify::Tsify; + macro_rules! make_brick_color { ({ $([ @@ -17,7 +19,7 @@ macro_rules! make_brick_color { /// /// Parts no longer use BrickColor, but we have conversions here to /// support older models. - #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[derive(Tsify, Debug, Clone, Copy, PartialEq, Eq)] #[repr(u16)] #[non_exhaustive] pub enum BrickColor { diff --git a/rbx_types/src/content.rs b/rbx_types/src/content.rs index f579acf78..ac4ccb25d 100644 --- a/rbx_types/src/content.rs +++ b/rbx_types/src/content.rs @@ -1,7 +1,9 @@ +use tsify::Tsify; + /// A reference to a Roblox asset. /// /// When exposed to Lua, this is just a string. -#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] +#[derive(Tsify, Debug, Clone, Default, PartialEq, Eq, Hash)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), diff --git a/rbx_types/src/faces.rs b/rbx_types/src/faces.rs index 9c68aeb3f..b234201c1 100644 --- a/rbx_types/src/faces.rs +++ b/rbx_types/src/faces.rs @@ -1,8 +1,11 @@ use std::fmt; +use tsify::Tsify; + use crate::lister::Lister; bitflags::bitflags! { + #[derive(Tsify)] struct FaceFlags: u8 { const RIGHT = 1; const TOP = 2; @@ -17,7 +20,7 @@ bitflags::bitflags! { /// /// ## See Also /// * [Faces on Roblox Developer Hub](https://developer.roblox.com/en-us/api-reference/datatype/Faces) -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Tsify, Clone, Copy, PartialEq, Eq)] pub struct Faces { flags: FaceFlags, } diff --git a/rbx_types/src/font.rs b/rbx_types/src/font.rs index a40d137ef..11a6d407e 100644 --- a/rbx_types/src/font.rs +++ b/rbx_types/src/font.rs @@ -1,4 +1,6 @@ -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)] +use tsify::Tsify; + +#[derive(Tsify, Debug, Copy, Clone, PartialEq, Eq, Hash, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FontWeight { Thin, @@ -43,7 +45,7 @@ impl FontWeight { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)] +#[derive(Tsify, Debug, Copy, Clone, PartialEq, Eq, Hash, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FontStyle { #[default] @@ -69,7 +71,7 @@ impl FontStyle { } /// A font face consisting of a typeface and other style properties. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Tsify, Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), diff --git a/rbx_types/src/material_colors.rs b/rbx_types/src/material_colors.rs index cbb375357..563a5d85b 100644 --- a/rbx_types/src/material_colors.rs +++ b/rbx_types/src/material_colors.rs @@ -1,12 +1,13 @@ use std::{collections::BTreeMap, str::FromStr}; use thiserror::Error; +use tsify::Tsify; use crate::Color3uint8; use crate::Error as CrateError; -#[derive(Debug, PartialEq, Clone, Default)] +#[derive(Tsify, Debug, PartialEq, Clone, Default)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), @@ -119,7 +120,7 @@ macro_rules! material_colors { const MATERIAL_ORDER: [TerrainMaterials; 21] = [$(TerrainMaterials::$name,)*]; /// All materials that are represented by `MaterialColors`. - #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] + #[derive(Tsify, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), diff --git a/rbx_types/src/physical_properties.rs b/rbx_types/src/physical_properties.rs index 4756069ea..c59f79b25 100644 --- a/rbx_types/src/physical_properties.rs +++ b/rbx_types/src/physical_properties.rs @@ -1,5 +1,6 @@ #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use tsify::Tsify; /// Represents the physical properties that parts can have. /// @@ -8,7 +9,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// that `PhysicalProperties` can have. /// /// [PhysicalProperties]: https://developer.roblox.com/en-us/api-reference/datatype/PhysicalProperties -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] pub enum PhysicalProperties { Default, Custom(CustomPhysicalProperties), @@ -26,7 +27,7 @@ impl From for PhysicalProperties { /// [`PhysicalProperties`][PhysicalProperties] DevHub documentation. /// /// [PhysicalProperties]: https://developer.roblox.com/en-us/api-reference/datatype/PhysicalProperties -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Tsify, Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct CustomPhysicalProperties { diff --git a/rbx_types/src/referent.rs b/rbx_types/src/referent.rs index 555708e71..1c6adcb33 100644 --- a/rbx_types/src/referent.rs +++ b/rbx_types/src/referent.rs @@ -5,9 +5,11 @@ use std::fmt; use std::num::NonZeroU128; use std::str::FromStr; +use tsify::Tsify; + /// An universally unique, optional reference to a Roblox instance. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct Ref(Option); +#[derive(Tsify, Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct Ref(#[tsify(type = "number")] Option); impl Ref { /// Generate a new random `Ref`. diff --git a/rbx_types/src/security_capabilities.rs b/rbx_types/src/security_capabilities.rs index 05a682a43..9f5486df7 100644 --- a/rbx_types/src/security_capabilities.rs +++ b/rbx_types/src/security_capabilities.rs @@ -1,4 +1,6 @@ -#[derive(Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +use tsify::Tsify; + +#[derive(Tsify, Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), diff --git a/rbx_types/src/shared_string.rs b/rbx_types/src/shared_string.rs index c449bbee1..ce1230a7e 100644 --- a/rbx_types/src/shared_string.rs +++ b/rbx_types/src/shared_string.rs @@ -7,6 +7,7 @@ use std::{ }; use blake3::Hash as Blake3Hash; +use tsify::Tsify; lazy_static::lazy_static! { static ref STRING_CACHE: Arc>>>> = { @@ -17,9 +18,10 @@ lazy_static::lazy_static! { /// A version of `BinaryString` used for data that's commonly repeated. /// `rbx_types` automatically deduplicates data as it's loaded into /// `SharedString` values. -#[derive(Debug, Clone)] +#[derive(Tsify, Debug, Clone)] pub struct SharedString { data: Option>>, + #[tsify(type = "Uint8Array")] hash: Blake3Hash, } diff --git a/rbx_types/src/tags.rs b/rbx_types/src/tags.rs index d3e49a93b..271bc7218 100644 --- a/rbx_types/src/tags.rs +++ b/rbx_types/src/tags.rs @@ -1,10 +1,12 @@ use std::string::FromUtf8Error; +use tsify::Tsify; + /// Contains a list of tags that can be applied to an instance. /// /// This object does not ensure that tags are unique; there may be duplicate /// values in the list of tags. -#[derive(Default, Clone, Debug, Eq, PartialEq)] +#[derive(Tsify, Default, Clone, Debug, Eq, PartialEq)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize), diff --git a/rbx_types/src/unique_id.rs b/rbx_types/src/unique_id.rs index eb392a7ef..4b21fa266 100644 --- a/rbx_types/src/unique_id.rs +++ b/rbx_types/src/unique_id.rs @@ -1,6 +1,7 @@ use lazy_static::lazy_static; use rand::{thread_rng, Rng}; use thiserror::Error; +use tsify::Tsify; use std::{ convert::TryFrom, @@ -38,7 +39,7 @@ pub(crate) enum UniqueIdError { } /// Represents a UUID with a custom epoch of midnight January 1st 2021. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] +#[derive(Tsify, Debug, Clone, Copy, Hash, PartialEq, Eq)] pub struct UniqueId { index: u32, time: u32, diff --git a/rbx_types/src/variant.rs b/rbx_types/src/variant.rs index 597c8747c..b5773cca0 100644 --- a/rbx_types/src/variant.rs +++ b/rbx_types/src/variant.rs @@ -5,6 +5,8 @@ use crate::{ UniqueId, Vector2, Vector2int16, Vector3, Vector3int16, }; +use tsify::Tsify; + /// Reduces boilerplate from listing different values of Variant by wrapping /// them into a macro. macro_rules! make_variant { @@ -21,7 +23,7 @@ macro_rules! make_variant { /// /// New variants may be added to `Variant` in minor releases. As /// such, it is marked `#[non_exhaustive]`. - #[derive(Debug, Clone, PartialEq)] + #[derive(Tsify, Debug, Clone, PartialEq)] #[non_exhaustive] #[cfg_attr( feature = "serde",