Skip to main content

cjc_runtime/
lib_registry.rs

1//! Library Registry — informational trait for CJC library self-description.
2//!
3//! CJC libraries implement this trait to declare their builtins, methods,
4//! and value types. This enables:
5//! - `:libs` REPL command for library discovery
6//! - LSP hover info for library-provided symbols
7//! - Future automated import validation
8//!
9//! Actual dispatch remains in library-specific dispatch modules
10//! (the proven match-arm pattern). This trait is for metadata only.
11
12/// Trait that CJC library crates implement for self-description.
13///
14/// # Example
15///
16/// ```ignore
17/// pub struct VizorLibrary;
18///
19/// impl CjcLibrary for VizorLibrary {
20///     fn name(&self) -> &'static str { "vizor" }
21///     fn version(&self) -> &'static str { "0.1.0" }
22///     fn builtin_names(&self) -> &[&'static str] { &["vizor_plot"] }
23///     fn method_names(&self) -> &[&'static str] { &["geom_point", "to_svg", "save"] }
24///     fn value_type_names(&self) -> &[&'static str] { &["VizorPlot"] }
25/// }
26/// ```
27pub trait CjcLibrary {
28    /// Library name (e.g., "vizor", "data").
29    fn name(&self) -> &'static str;
30
31    /// Library version string.
32    fn version(&self) -> &'static str;
33
34    /// List of free-function builtin names this library provides.
35    fn builtin_names(&self) -> &[&'static str];
36
37    /// List of method names this library handles on its types.
38    fn method_names(&self) -> &[&'static str];
39
40    /// List of Value variant type names this library introduces.
41    fn value_type_names(&self) -> &[&'static str];
42}