pub struct FsLoader { /* private fields */ }Expand description
Loader that reads files from the filesystem with std::fs::read_to_string.
This is the production loader used by the CLI; the LSP wraps it with a
file-watch invalidation layer in PR 8. lex-core’s resolver code does not
reference std::fs — FsLoader is the one place where it does, isolated
behind the Loader trait so the rest of the crate stays sandbox- and
WASM-friendly.
FsLoader is constructed with the resolution root and rechecks every
load against it post-fs::canonicalize, so a symlink pointing outside
the root is rejected even though the lexical-only check in
[resolve_path] cannot see it. Also rejects non-regular files (devices,
FIFOs, directories) before reading, so the loader can’t be tricked into
blocking on /dev/zero or allocating against an open device.
Errors map:
- canonicalization fails (file missing, permission denied at a parent,
broken symlink, …) →
LoadError::NotFound - canonical path doesn’t sit under canonical root →
LoadError::OutsideRoot - target is not a regular file →
LoadError::Iowith a clear message - any other I/O error during read →
LoadError::Io
Implementations§
Source§impl FsLoader
impl FsLoader
Sourcepub const DEFAULT_MAX_FILE_SIZE: u64
pub const DEFAULT_MAX_FILE_SIZE: u64
Default per-file size cap: 10 MiB. Generous for realistic Lex source documents (text only) and tight enough to bound memory allocation per include against an adversarial 1 GB file.
Sourcepub fn new(root: PathBuf) -> Self
pub fn new(root: PathBuf) -> Self
Construct a loader rooted at root with default size limits.
The loader stores root’s fs-canonical form (with symlinks
resolved); subsequent loads validate that the requested path’s
canonical form lives under it.
Sourcepub fn with_max_file_size(self, max_file_size: u64) -> Self
pub fn with_max_file_size(self, max_file_size: u64) -> Self
Override the default per-file size cap (bytes). Use to widen the limit for projects with genuinely large source files, or tighten it for stricter sandboxes (e.g., LSPs serving untrusted content).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FsLoader
impl RefUnwindSafe for FsLoader
impl Send for FsLoader
impl Sync for FsLoader
impl Unpin for FsLoader
impl UnsafeUnpin for FsLoader
impl UnwindSafe for FsLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more