[core] API: compiling Seam 1 skeleton (types, signatures, stubs)

This commit is contained in:
2026-11-22 22:58:26 +01:00
parent 8f2bf986af
commit 5c17aac8d4
19 changed files with 1084 additions and 1 deletions
+104
View File
@@ -0,0 +1,104 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
use crate::error::ParseError;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
/// An absolute Windows path with a drive letter, checked and normalised.
///
/// Refused: anything not starting with `X:\` (so UNC `\\server\share`, `\\?\` and `\\.\` too), `.` and `..`
/// components, NUL and other control characters, `<>:"|?*` (a `:` only after the drive letter), device names
/// (`CON`, `NUL`, `COM1`, ...) as any component, components ending in a dot or a space, and paths over
/// [`crate::limits::MAX_PATH`] UTF-16 units. Normalised: `/` becomes `\`, repeated separators collapse, the drive
/// letter is uppercase and a trailing separator is dropped (except on the drive root `X:\`).
///
/// Equality is exact on the normalised text; [`WinPath::eq_ignore_case`] compares the way Windows does.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
pub struct WinPath(String);
impl WinPath {
/// Checks and normalises `s`.
pub fn parse(s: &str) -> Result<WinPath, ParseError> {
let _ = s;
Err(ParseError::BadPath("path"))
}
pub fn as_str(&self) -> &str {
&self.0
}
/// Appends a relative path (`a\b` or `a/b`); the same component rules apply and it may not climb out.
pub fn join(&self, relative: &str) -> Result<WinPath, ParseError> {
let _ = relative;
Err(ParseError::BadPath("path"))
}
/// The containing folder, or `None` for a drive root.
pub fn parent(&self) -> Option<WinPath> {
None
}
/// The last component, or `None` for a drive root.
pub fn file_name(&self) -> Option<&str> {
None
}
/// The components after the drive root.
pub fn components(&self) -> impl Iterator<Item = &str> {
std::iter::empty()
}
/// The case-folded form Windows treats as the same place, for comparing and deduping.
pub fn key(&self) -> String {
self.0.to_lowercase()
}
/// True when both name the same place, ignoring case.
pub fn eq_ignore_case(&self, other: &WinPath) -> bool {
self.key() == other.key()
}
/// True when `self` is `base` or lies inside it (component-wise, ignoring case).
pub fn starts_with(&self, base: &WinPath) -> bool {
let _ = base;
false
}
}
impl fmt::Display for WinPath {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl FromStr for WinPath {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
WinPath::parse(s)
}
}
impl TryFrom<String> for WinPath {
type Error = ParseError;
fn try_from(s: String) -> Result<Self, Self::Error> {
WinPath::parse(&s)
}
}
impl From<WinPath> for String {
fn from(p: WinPath) -> String {
p.0
}
}
impl AsRef<str> for WinPath {
fn as_ref(&self) -> &str {
&self.0
}
}