Skip to main content

vane_core/
lib.rs

1//! Foundation types, traits, `FlowGraph` IR, and compilation pipeline for vane.
2//!
3//! See `spec/architecture/03-types.md`, `02-flow.md`, `04-middleware.md`.
4
5pub mod body;
6pub use body::*;
7pub mod compile;
8pub use compile::compile;
9pub mod conn_context;
10pub use conn_context::*;
11pub mod error;
12pub use error::*;
13pub mod fetch;
14pub use fetch::*;
15pub mod flow_ctx;
16pub use flow_ctx::*;
17pub mod flow_log;
18pub use flow_log::*;
19pub mod ir;
20pub use ir::*;
21pub mod l4;
22pub use l4::*;
23pub mod metadata;
24pub use metadata::*;
25pub mod middleware;
26pub use middleware::*;
27pub mod phase;
28pub mod predicate;
29pub use predicate::*;
30pub mod rule;
31
32pub mod meta {
33	pub const DESCRIPTION: &str = "A compact programmable proxy engine";
34	pub const COPYRIGHT: &str = "Copyright (C) 2025 Canmi <t@canmi.icu>";
35	pub const HOMEPAGE: &str = "https://vane.canmi.app";
36	pub const REPOSITORY: &str = "https://github.com/canmi21/vane";
37	pub const LICENSE: &str = "MIT";
38	pub const LICENSE_URL: &str = "https://opensource.org/licenses/MIT";
39}
40
41pub mod version {
42	use std::fmt::Write as _;
43
44	use super::meta::{COPYRIGHT, DESCRIPTION, HOMEPAGE, LICENSE_URL, REPOSITORY};
45
46	/// Compile-time and runtime information about a vane binary.
47	///
48	/// Constructed by each binary from its own `build.rs`-emitted env vars
49	/// and `cfg!(feature = ...)` introspection. See
50	/// `spec/architecture/16-crate-layout.md`.
51	pub struct BuildInfo {
52		pub version: &'static str,
53		pub commit: &'static str,
54		pub build_date: &'static str,
55		pub rustc: &'static str,
56		pub cargo: &'static str,
57		pub features: &'static [&'static str],
58		pub protocols: &'static [&'static str],
59	}
60
61	/// Format the shared version banner used by both `vane` and `vaned`.
62	///
63	/// Every content line is indented with two spaces; the output is bracketed
64	/// by a leading and trailing blank line for vertical breathing room in the
65	/// terminal.
66	///
67	/// Layout:
68	/// ```text
69	///
70	///   Vane — A compact programmable proxy engine
71	///
72	///   Built:      <version> (<commit> <date>)
73	///   Rust:       <rustc-version-line>
74	///   Cargo:      <cargo-version-line>
75	///   Features:   ...                              (vaned only)
76	///   Protocols:  ...                              (vaned only)
77	///
78	///   Copyright (C) 2025 Canmi <t@canmi.icu>
79	///
80	///   Released under the MIT License without restriction.
81	///   This software comes with ABSOLUTELY NO WARRANTY.
82	///
83	///   Homepage:   https://vane.canmi.app
84	///   Source:     https://github.com/canmi21/vane
85	///   License:    https://opensource.org/licenses/MIT
86	///
87	/// ```
88	#[must_use]
89	pub fn format_version(info: &BuildInfo) -> String {
90		const WIDTH: usize = 12;
91		const INDENT: &str = "  ";
92		let mut out = String::new();
93
94		let _ = writeln!(out);
95		let _ = writeln!(out, "{INDENT}Vane — {DESCRIPTION}");
96		let _ = writeln!(out);
97
98		let _ = writeln!(
99			out,
100			"{INDENT}{label:<WIDTH$}{version} ({commit} {date})",
101			label = "Built:",
102			version = info.version,
103			commit = info.commit,
104			date = info.build_date,
105		);
106		let _ = writeln!(out, "{INDENT}{label:<WIDTH$}{value}", label = "Rust:", value = info.rustc);
107		let _ = writeln!(out, "{INDENT}{label:<WIDTH$}{value}", label = "Cargo:", value = info.cargo);
108		if !info.features.is_empty() {
109			let _ = writeln!(
110				out,
111				"{INDENT}{label:<WIDTH$}{value}",
112				label = "Features:",
113				value = info.features.join(", "),
114			);
115		}
116		if !info.protocols.is_empty() {
117			let _ = writeln!(
118				out,
119				"{INDENT}{label:<WIDTH$}{value}",
120				label = "Protocols:",
121				value = info.protocols.join(", "),
122			);
123		}
124		let _ = writeln!(out);
125		let _ = writeln!(out, "{INDENT}{COPYRIGHT}");
126		let _ = writeln!(out);
127		let _ = writeln!(out, "{INDENT}Released under the MIT License without restriction.");
128		let _ = writeln!(out, "{INDENT}This software comes with ABSOLUTELY NO WARRANTY.");
129		let _ = writeln!(out);
130		let _ = writeln!(out, "{INDENT}{label:<WIDTH$}{HOMEPAGE}", label = "Homepage:");
131		let _ = writeln!(out, "{INDENT}{label:<WIDTH$}{REPOSITORY}", label = "Source:");
132		let _ = writeln!(out, "{INDENT}{label:<WIDTH$}{LICENSE_URL}", label = "License:");
133		let _ = writeln!(out);
134
135		out
136	}
137}