(enum)
enum declarations and scoped variant references
clojure
(enum name? variant?)Where:
Matching:
- declarations, e.g.
enum Color {} - variant references, e.g.
Color::Red
Behavior
- With no arguments, matches only declarations.
- With a name, matches both the declaration and all variant references.
- With name and variant, matches only that specific variant reference.
Examples
Find enums missing #[non_exhaustive] before making them public API.
clojure
(:and (enum) (:not (:text "non_exhaustive")))Selects in lines { 7 } but not in { 2 }:
rust
#[non_exhaustive]
pub enum Status {
Ok,
Error,
}
pub enum Color {
Red,
Blue,
}Migrate away from a legacy enum by finding its declaration and every place its variants are used.
clojure
(enum Color)Selects in lines { 1, 13, 14 } but not in { 6, 17 }:
rust
enum Color {
Red,
Blue,
}
enum Shade {
Light,
Dark,
}
fn paint(c: Color, s: Shade) {
match c {
Color::Red => {}
Color::Blue => {}
}
let _ = Shade::Light;
}Replace a deprecated variant by locating all uses of Color::Red.
clojure
(enum Color Red)Selects in lines { 13 } but not in { 1, 14, 17 }:
rust
enum Color {
Red,
Blue,
}
enum Shade {
Red,
Dark,
}
fn paint(c: Color, s: Shade) {
match c {
Color::Red => {}
Color::Blue => {}
}
let _ = Shade::Red;
}Arguments
name
• Identifier: shorthand for (id)
• Pattern: shorthand for (id)
• (id)
• (:into) • (:and) • (:or) • (:not) • (:text) • (:kind) • (:replace) • (:capture)