rockbox/smart_playlists/rules
Composable builder for smart-playlist rule sets. Pipe-friendly.
import rockbox/smart_playlists
import rockbox/smart_playlists/rules
let r =
rules.all_of()
|> rules.where("play_count", rules.Gte, rules.int(10))
|> rules.where("last_played", rules.Within, rules.string("30d"))
|> rules.sort("play_count", rules.Desc)
|> rules.limit(50)
let input = smart_playlists.new("Most played", rules.to_string(r))
let assert Ok(_) = smart_playlists.create(client, input)
any_of() swaps the top-level operator from AND to OR. Mix the two by
nesting builders with where_group:
let r =
rules.all_of()
|> rules.where("genre", rules.Eq, rules.string("Rock"))
|> rules.where_group(
rules.any_of()
|> rules.where("year", rules.Gte, rules.int(2000))
|> rules.where("year", rules.Lte, rules.int(2010)),
)
Types
Comparison operators understood by the server.
| Variant | Meaning |
|---|---|
Eq | equals |
Neq | not equals |
Gt | greater than |
Gte | greater than or equal |
Lt | less than |
Lte | less than or equal |
Contains | substring match |
Within | duration window (e.g. "30d", "7d") |
pub type Op {
Eq
Neq
Gt
Gte
Lt
Lte
Contains
Within
}
Constructors
-
Eq -
Neq -
Gt -
Gte -
Lt -
Lte -
Contains -
Within
A composable rule set. Build with all_of / any_of and chain
where / sort / limit. Hand to to_string to get the JSON payload
the GraphQL createSmartPlaylist mutation expects.
pub opaque type Rules
Values
pub fn raw(value: json.Json) -> Value
Escape hatch for arbitrary JSON values (arrays, nested objects, etc.).
pub fn string(value: String) -> Value
Wrap a string (e.g. titles, artists, genres, duration windows).
pub fn to_json(builder: Rules) -> json.Json
Encode the builder as a Json value — useful if you’re already working
with JSON values.
pub fn to_string(builder: Rules) -> String
Encode the builder as a JSON string ready for the smart-playlist mutation.
pub fn where(
builder: Rules,
field: String,
op: Op,
value: Value,
) -> Rules
Append a rule to the current group.