README

jingmo653/sshconfig-resolve/loader does not have a README file

#
FileSystem

pub(open) trait FileSystem {
fn read_text(Self, String, max_bytes? : Int) -> Result[String, FileSystemError]
fn canonical_identity(Self, String) -> Result[String, FileSystemError]
fn glob(Self, String, max_matches? : Int) -> Result[Array[String], FileSystemError]
fn home_dir(Self) -> String?
}

The backend boundary used by the portable configuration loader.

Implementations provide text, an identity used exclusively for cycle detection, deterministic-enough glob candidates, and an explicitly injected home directory. The loader sorts glob output itself and never consults process state.

Implementations must honor supplied limits before returning an oversized value. Adapters with streaming or metadata support should stop I/O before allocation; adapters without it must reject before transferring the value to the loader and document the residual backend allocation boundary.

#
FileSystemError

pub(all) suberror FileSystemError {
NotFound(path~ : String)
PermissionDenied(path~ : String)
InvalidPath(path~ : String, message~ : String)
ReadByteLimitExceeded(path~ : String, limit~ : Int)
GlobMatchLimitExceeded(path~ : String, limit~ : Int)
Other(message~ : String)
} derive(Eq,
Debug
)

Errors produced by a filesystem adapter.

The loader translates these values into LoadError, so adapters never leak platform-specific error types through the public loading API.

#
LoadError

pub(all) suberror LoadError {
ReadFailed(path~ : String, message~ : String)
IncludeCycle(chain~ : Array[String])
IncludeDepthExceeded(limit~ : Int, chain~ : Array[String])
FileLimitExceeded(limit~ : Int)
FileTooLarge(path~ : String, limit~ : Int)
TotalBytesExceeded(limit~ : Int)
GlobLimitExceeded(path~ : String, limit~ : Int)
IncludeArgumentLimitExceeded(limit~ : Int, location~ :
SourceLocation
)
InvalidInclude(location~ :
SourceLocation
, message~ : String)
ParseFailed(location~ :
SourceLocation
, message~ : String)
InvalidOptions(message~ : String)
Detailed(failure~ : LoadFailure)
} derive(Eq,
Debug
)

Loading failures, including resource-limit failures which are never converted into non-fatal missing-Include diagnostics.

The original constructors are retained for compatibility with callers that construct or classify legacy values. load itself raises Detailed.

#
LoadDiagnostic

pub(all) enum LoadDiagnostic {
MissingInclude(path~ : String, included_from~ :
SourceLocation
?)
} derive(Eq,
Debug
)

A non-fatal event retained for callers that need diagnostics without changing the configured missing-Include policy.

#
LoadFailure

pub(all) struct LoadFailure {
kind : LoadFailureKind
attempted_path : String
location :
SourceLocation
?
include_location :
SourceLocation
?
chain : Array[String]
message : String
} derive(Eq,
Debug
)

Context retained for every failure raised by load.

chain uses display paths, begins at the root, and includes attempted_path for file-loading failures. For a glob or malformed Include argument, the attempted value is kept separately while chain identifies the active file stack.

#
LoadFailureKind

pub(all) enum LoadFailureKind {
ReadFailed
GlobFailed
IncludeCycle
IncludeDepthExceeded(limit~ : Int)
FileLimitExceeded(limit~ : Int)
FileTooLarge(limit~ : Int)
TotalBytesExceeded(limit~ : Int)
GlobLimitExceeded(limit~ : Int)
IncludeArgumentLimitExceeded(limit~ : Int)
InvalidInclude
ParseFailed
InvalidOptions
} derive(Eq,
Debug
)

Stable categories for a context-rich loading failure.

The legacy LoadError constructors remain available for source compatibility. New loader code raises LoadError::Detailed so every operational failure can retain the attempted path, Include location, and complete display-path chain.

#
LoadOptions

pub(all) struct LoadOptions {
max_depth : Int
max_files : Int
max_file_bytes : Int
max_total_bytes : Int
max_glob_matches : Int
max_include_arguments : Int
missing_include : MissingIncludePolicy
relative_include_base : String?
} derive(Eq,
Debug
)

Resource and compatibility limits for a single load operation.

Every limit is checked before the corresponding counter is incremented.

#
LoadOptions::default

fn LoadOptions::default() -> LoadOptions

The conservative defaults used by load when no options are supplied.

#
LoadedConfig

pub(all) struct LoadedConfig {
config :
Config

sources : Array[SourceFile]
diagnostics : Array[LoadDiagnostic]
} derive(Eq,
Debug
)

A parsed configuration together with all source provenance and diagnostics.

config is parsed with the supplied display path and has every Include recursively expanded in source order.

#
MemoryFileSystem

pub struct MemoryFileSystem {
// private fields
}

Deterministic, in-memory filesystem for tests, tools, and non-native hosts. All stored paths are normalized at construction time.

Fields stay private so callers cannot bypass path normalization or forge adapter counters. Mutation remains available through put.

#
MemoryFileSystem::as_file_system

fn MemoryFileSystem::as_file_system(self : MemoryFileSystem) -> &FileSystem

View this deterministic implementation through the portable backend trait.

#
MemoryFileSystem::glob_count

fn MemoryFileSystem::glob_count(self : MemoryFileSystem) -> Int

Number of glob calls made through the FileSystem interface.

#
MemoryFileSystem::new

fn MemoryFileSystem::new(files : Map[String, String], home? : String) -> MemoryFileSystem

Create an in-memory filesystem from display paths and text contents.

#
MemoryFileSystem::put

fn MemoryFileSystem::put(self : MemoryFileSystem, path : String, text : String) -> Unit

Update or add a virtual file using its normalized path.

#
MemoryFileSystem::read_count

fn MemoryFileSystem::read_count(self : MemoryFileSystem) -> Int

Number of read_text calls made through the FileSystem interface.

#
MissingIncludePolicy

pub(all) enum MissingIncludePolicy {
Ignore
Warn
Error
} derive(Eq,
Debug
)

Behaviour when an Include pattern has no matching files.

#
SourceFile

pub(all) struct SourceFile {
identity : String
display_path : String
included_from :
SourceLocation
?
} derive(Eq,
Debug
)

Provenance for one physical configuration source read during loading.

#
join_path

fn join_path(base : String, child : String) -> String

Combine a base directory and a child path without probing the filesystem.

#
load

fn load(fs : &FileSystem, path : String, options? : LoadOptions) -> LoadedConfig raise LoadError

Read, parse, and recursively expand an OpenSSH configuration root.

By default Include patterns are resolved relative to their including file. Set LoadOptions::relative_include_base for a configuration domain such as OpenSSH's user ~/.ssh base. ~/ is expanded only through FileSystem::home_dir, and every glob result is sorted before recursive loading. The same file may be included twice from separate branches; only the active recursion chain is considered a cycle.

#
normalize_path

fn normalize_path(path : String) -> String

Normalize portable Unix-style path segments without consulting a filesystem.

Leading .. segments in a relative path are retained. This deliberately does not resolve symlinks; adapters provide canonical identities for that.

#
parent_directory

fn parent_directory(path : String) -> String

Return the normalized parent directory of a display path.

#
path_has_home_prefix

fn path_has_home_prefix(path : String) -> Bool

Returns whether path is exactly ~ or starts with ~/.

#
path_is_absolute

fn path_is_absolute(path : String) -> Bool

Returns whether path is an absolute Unix-style path.

Drive letters and UNC paths are intentionally left to a platform adapter.

#
resolve_include_path

fn resolve_include_path(including_path : String, include_path : String, home : String?) -> Result[String, String]

Resolve an Include argument against its including file and explicitly injected home directory. It never reads process environment variables.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io