You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's do that. I propose that we could also combine it with #94.
Preferred API
This would be the API we recommend to users:
let source=Source::from_file(path);
This would:
Initialize a Source with the provided path, and SourceType as deduced from the path's file extension.
Read the file from file system (using fast SIMD UTF-8 validation).
A one-stop shop!
Full API
We can also provide other ways to create a Source for advanced use cases:
structSource<'a>{source_text:&'a str,source_type:SourceType,path:Option<Path>,// or `PathBuf`?}// Methods to create a `Source`impl<'a>Source<'a>{// Load source text into arenafnfrom_file(path:Path,allocator:&'a Allocator) -> Self;fnfrom_reader<R: std::io::Read>(reader:R,size:Option<usize>,allocator:&'a Allocator) -> Self;// From string already in arenafnfrom_arena_string(source_text: oxc_allocator::String<'a>) -> Self;// From borrowed typesfnfrom_str<'s:'a>(source_text:&'s str,allocator:&'a Allocator) -> Self;fnfrom_bytes<'s:'a>(source_text:&'s [u8],allocator:&'a Allocator) -> Self;}// Methods to override source type and pathimpl<'a>Source<'a>{fnwith_type(&mutself,source_type:SourceType);fnwith_path(&mutself,path:Path);}
from_file and from_reader take an &Allocator. It's ideal if they load the source text into the arena, for the reasons discussed in #94 (re-use allocations, warm cache).
My suggestion is that from_str and from_bytes also take an &Allocator. They don't need to right now, but if we decide in future that we always need source text to be in the arena, then we could make that change without breaking changes to the public API.
The text was updated successfully, but these errors were encountered:
@Boshen said in oxc-project/oxc#6248 (comment):
Let's do that. I propose that we could also combine it with #94.
Preferred API
This would be the API we recommend to users:
This would:
Source
with the provided path, andSourceType
as deduced from the path's file extension.A one-stop shop!
Full API
We can also provide other ways to create a
Source
for advanced use cases:from_file
andfrom_reader
take an&Allocator
. It's ideal if they load the source text into the arena, for the reasons discussed in #94 (re-use allocations, warm cache).My suggestion is that
from_str
andfrom_bytes
also take an&Allocator
. They don't need to right now, but if we decide in future that we always need source text to be in the arena, then we could make that change without breaking changes to the public API.The text was updated successfully, but these errors were encountered: