pub struct Theme { /* private fields */ }Expand description
An index of the cursor themes on disk.
Cheap to construct – a directory walk and a small metadata parse, no pixels. Resolutions are memoized for the index’s lifetime, hits and misses alike, so a caller cycling through a fixed set of shapes pays the walk once per name.
The index is a snapshot: cursors appearing or disappearing on disk afterwards are not noticed. Build a new one, which is cheap.
Not Sync. The memo cache is a RefCell, matching the reference, which
documents Theme as unsynchronized. Sharing one across threads is a
compile error rather than a race.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn discover() -> Result<Self, CursorError>
pub fn discover() -> Result<Self, CursorError>
Index the themes on the standard search path.
§Errors
CursorError::NoThemes when no theme directory is readable at all.
That is deliberately distinct from a resolve failing on a healthy
index: one means nothing is installed, the other means this cursor is
not in what is installed, and a caller wants to say different things
about them.
Sourcepub fn discover_with_paths(
search_paths: &[PathBuf],
) -> Result<Self, CursorError>
pub fn discover_with_paths( search_paths: &[PathBuf], ) -> Result<Self, CursorError>
Index the themes under an explicit set of roots.
The seam the tests use, so they can point at a fixture tree rather than whatever the machine happens to have installed.
§Errors
As Theme::discover.
Sourcepub fn search_paths(&self) -> &[PathBuf]
pub fn search_paths(&self) -> &[PathBuf]
The roots this index was built from.
Sourcepub fn theme_names(&self) -> Vec<&str>
pub fn theme_names(&self) -> Vec<&str>
The themes indexed, in discovery order.
Sourcepub fn resolve(
&self,
cursor_name: &str,
preferred_theme: &str,
) -> Result<ThemeResolution, CursorError>
pub fn resolve( &self, cursor_name: &str, preferred_theme: &str, ) -> Result<ThemeResolution, CursorError>
Resolve a cursor name to a file.
preferred_theme may be empty, in which case $XCURSOR_THEME is used,
then default. The Inherits= chain is followed breadth-first and
every alias of the name is tried in each theme.
§Errors
CursorError::InvalidNamefor a name that is empty,.,.., or contains a path separator.CursorError::NotFoundif no theme on the search path has it.