#![allow(dead_code)]
use std::ffi::OsString;
#[derive(Debug)]
pub struct ServerBootstrapError {
reason: &'static str,
}
impl ServerBootstrapError {
fn activation_pending() -> Self {
Self {
reason: "server_api::run is not wired until the V11 activation cut",
}
}
}
impl std::fmt::Display for ServerBootstrapError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.reason)
}
}
impl std::error::Error for ServerBootstrapError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServerExit {
RefusedToStart,
Success,
}
pub fn run(_args: Vec<OsString>) -> Result<ServerExit, ServerBootstrapError> {
Err(ServerBootstrapError::activation_pending())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dark_run_refuses_and_the_contract_shapes_hold() {
let refusal = run(Vec::new())
.expect_err("the stand-in refuses; a server run nothing performed is not reported");
let rendered = format!("{refusal}");
assert!(
rendered.contains("activation cut"),
"Display names the cut: {rendered}"
);
let _as_error: &dyn std::error::Error = &refusal;
let exits = [ServerExit::RefusedToStart, ServerExit::Success];
for exit in exits {
match exit {
ServerExit::RefusedToStart | ServerExit::Success => {}
}
}
fn all_five_auto<
T: Send + Sync + Unpin + std::panic::RefUnwindSafe + std::panic::UnwindSafe,
>() {
}
all_five_auto::<ServerBootstrapError>();
all_five_auto::<ServerExit>();
}
#[test]
fn bootstrap_error_is_an_opaque_struct_not_an_enum() {
let source = include_str!("server_api.rs");
let struct_needle = format!("\n{} ServerBootstrapError", "pub struct");
let enum_needle = format!("\n{} ServerBootstrapError", "pub enum");
assert!(
source.contains(&struct_needle),
"the contract pins kind: struct"
);
assert!(
!source.contains(&enum_needle),
"an enum here is the invented-surface defect the contract's \
opaque struct exists to prevent"
);
let declaration = source
.split(struct_needle.as_str())
.nth(1)
.expect("declaration present");
let after_name = declaration.trim_start();
assert!(
after_name.starts_with('{'),
"the declaration must open a brace body immediately — a tuple \
struct's parenthesized fields would evade the field scan"
);
let body_end = after_name.find('}').expect("struct body closes");
let body = &after_name[1..body_end];
assert!(
!body.contains("pub "),
"has_nonpublic_fields: every field stays private, got: {body}"
);
}
}