@@ -190,17 +190,20 @@ impl StaticSourceMap {
190190 }
191191
192192 pub fn from_json ( json : String ) -> Result < Self > {
193- let borrowed_value_cell =
194- BorrowedValueCell :: try_new ( json. into_bytes ( ) , |owner| {
195- // We need a mutable slice from our owned data
196- // SAFETY: We're creating a mutable reference to the owned data.
197- // The self_cell ensures this reference is valid for the lifetime of the cell.
198- #[ allow( unsafe_code) ]
199- let bytes: & ' static mut [ u8 ] = unsafe {
200- std:: slice:: from_raw_parts_mut ( owner. as_ptr ( ) . cast_mut ( ) , owner. len ( ) )
201- } ;
202- simd_json:: to_borrowed_value ( bytes)
203- } ) ?;
193+ Self :: from_slice ( json. into_bytes ( ) )
194+ }
195+
196+ pub fn from_slice ( slice : Vec < u8 > ) -> Result < Self > {
197+ let borrowed_value_cell = BorrowedValueCell :: try_new ( slice, |owner| {
198+ // We need a mutable slice from our owned data
199+ // SAFETY: We're creating a mutable reference to the owned data.
200+ // The self_cell ensures this reference is valid for the lifetime of the cell.
201+ #[ allow( unsafe_code) ]
202+ let bytes: & ' static mut [ u8 ] = unsafe {
203+ std:: slice:: from_raw_parts_mut ( owner. as_ptr ( ) . cast_mut ( ) , owner. len ( ) )
204+ } ;
205+ simd_json:: to_borrowed_value ( bytes)
206+ } ) ?;
204207 Ok ( Self :: from_borrowed_value_cell ( Arc :: new (
205208 borrowed_value_cell,
206209 ) ) )
@@ -534,6 +537,12 @@ impl SourceMap {
534537 Self :: from_json ( json)
535538 }
536539
540+ /// Creates a [SourceMap] from a byte slice containing JSON data.
541+ pub fn from_slice ( slice : impl Into < Vec < u8 > > ) -> Result < SourceMap > {
542+ let s = StaticSourceMap :: from_slice ( slice. into ( ) ) ?;
543+ Ok ( SourceMap ( SourceMapCell :: Static ( s. into ( ) ) ) )
544+ }
545+
537546 /// Generate source map to a json string.
538547 pub fn to_json ( & self ) -> Result < String > {
539548 match & self . 0 {
0 commit comments