@@ -3,9 +3,9 @@ use std::sync::{Arc, Mutex, MutexGuard};
3
3
use rust_xlsxwriter as xlsx;
4
4
use wasm_bindgen:: prelude:: * ;
5
5
6
- use crate :: { error :: XlsxError , wrapper :: utils , DeepClone } ;
6
+ use crate :: { DeepClone } ;
7
7
8
- use super :: { color:: Color , WasmResult } ;
8
+ use super :: { color:: Color } ;
9
9
10
10
/// The `Format` struct is used to define cell formatting for data in a
11
11
/// worksheet.
@@ -178,32 +178,15 @@ pub struct Format {
178
178
pub ( crate ) inner : Arc < Mutex < xlsx:: Format > > ,
179
179
}
180
180
181
- #[ wasm_bindgen]
182
- extern "C" {
183
- #[ wasm_bindgen( typescript_type = "Format" ) ]
184
- pub type JsFormat ;
185
- }
186
-
187
181
#[ wasm_bindgen]
188
182
impl Format {
189
183
/// Create a new Format object.
190
184
///
191
185
/// Create a new Format object to use with worksheet formatting.
192
- /// If a Format obejct is provided as an argument, it will be cloned.
193
186
#[ wasm_bindgen( constructor) ]
194
- pub fn new ( format : Option < JsFormat > ) -> WasmResult < Format > {
195
- if let Some ( format) = format {
196
- // HACK: Since wasm-bindgen does not supports Option<&RustStruct>, we cast JsValue as Format.
197
- let format = utils:: format_of_jsval ( & format) . ok_or ( XlsxError :: Type (
198
- "Expected a value of type Format" . to_string ( ) ,
199
- ) ) ?;
200
- // Clone the inner object
201
- let format = format. deep_clone ( ) ;
202
- Ok ( format)
203
- } else {
204
- Ok ( Format {
205
- inner : Arc :: new ( Mutex :: new ( xlsx:: Format :: new ( ) ) ) ,
206
- } )
187
+ pub fn new ( ) -> Format {
188
+ Format {
189
+ inner : Arc :: new ( Mutex :: new ( xlsx:: Format :: new ( ) ) ) ,
207
190
}
208
191
}
209
192
@@ -815,6 +798,11 @@ impl Format {
815
798
inner : Arc :: clone ( & self . inner ) ,
816
799
}
817
800
}
801
+
802
+ #[ wasm_bindgen( js_name = "clone" ) ]
803
+ pub fn clone_format ( & self ) -> Format {
804
+ self . deep_clone ( )
805
+ }
818
806
}
819
807
820
808
impl DeepClone for Format {
0 commit comments