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:
| Path | Returns |
|---|---|
colors.background | Background color as hex |
typography.family | Primary font family name |
radius.button | Button radius in pixels |
bar.height | Bar 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§
Sourcefn get_color(&self, theme: &Theme, name: &str) -> Result<String>
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 queryname— 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.