File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -190,8 +190,12 @@ impl StaticSourceMap {
190190 }
191191
192192 pub fn from_json ( json : String ) -> Result < Self > {
193+ Self :: from_slice ( json. into_bytes ( ) )
194+ }
195+
196+ pub fn from_slice ( slice : Vec < u8 > ) -> Result < Self > {
193197 let borrowed_value_cell =
194- BorrowedValueCell :: try_new ( json . into_bytes ( ) , |owner| {
198+ BorrowedValueCell :: try_new ( slice , |owner| {
195199 // We need a mutable slice from our owned data
196200 // SAFETY: We're creating a mutable reference to the owned data.
197201 // The self_cell ensures this reference is valid for the lifetime of the cell.
@@ -534,6 +538,12 @@ impl SourceMap {
534538 Self :: from_json ( json)
535539 }
536540
541+ /// Creates a [SourceMap] from a byte slice containing JSON data.
542+ pub fn from_slice ( slice : impl Into < Vec < u8 > > ) -> Result < SourceMap > {
543+ let s = StaticSourceMap :: from_slice ( slice. into ( ) ) ?;
544+ Ok ( SourceMap ( SourceMapCell :: Static ( s. into ( ) ) ) )
545+ }
546+
537547 /// Generate source map to a json string.
538548 pub fn to_json ( & self ) -> Result < String > {
539549 match & self . 0 {
You can’t perform that action at this time.
0 commit comments