Trait QueryPort

Source
pub trait QueryPort: Send + Sync {
    // Required methods
    fn get(&self, theme: &Theme, path: &str) -> Result<String>;
    fn get_color(&self, theme: &Theme, name: &str) -> Result<String>;
    fn available_paths(&self) -> Vec<&'static str>;
}
Expand description

Port for querying theme values.

QueryPort provides a way to query specific values from a theme using string-based paths. This is useful for:

  • CLI tools that need to extract specific values
  • Templates that reference theme tokens by name
  • Testing that specific tokens have expected values

§Query Paths

Queries use dot-separated paths to navigate the theme structure:

PathReturns
colors.backgroundBackground color as hex
typography.familyPrimary font family name
radius.buttonButton radius in pixels
bar.heightBar height in pixels

§Example

ⓘ
use fernctl::ports::inbound::QueryPort;

let query = DefaultQueryAdapter::new();
let theme = Theme::dark();

// Query color
let bg = query.get(&theme, "colors.background")?;
assert_eq!(bg, "#1e1e2e");

// Query number
let height = query.get(&theme, "bar.height")?;
assert_eq!(height, "40");

Required Methods§

Source

fn get(&self, theme: &Theme, path: &str) -> Result<String>

Queries a value from the theme by path.

§Arguments
  • theme — The theme to query
  • path — Dot-separated path to the value
§Returns

The value as a string representation.

§Errors

Returns an error if the path does not exist in the theme.

§Example
ⓘ
let color = query.get(&theme, "colors.accent")?;
Source

fn get_color(&self, theme: &Theme, name: &str) -> Result<String>

Queries a color value from the theme.

This is a typed version of [get] that returns the color in hex format.

§Arguments
  • theme — The theme to query
  • name — The color name (e.g., “background”, “accent”)
§Returns

The color as a hex string (e.g., “#1e1e2e”).

§Errors

Returns an error if the color name is not recognized.

Source

fn available_paths(&self) -> Vec<&'static str>

Returns all available query paths.

Useful for auto-completion and documentation.

§Example
ⓘ
for path in query.available_paths() {
    println!("  {}", path);
}

Implementors§