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