Sort

Derive Macro Sort 

Source
#[derive(Sort)]
{
    // Attributes available to this derive:
    #[teil]
}
Expand description

Implements the Sort trait to an enum

This derive macro allows for simple trait implementation for simple enums. The following is a list of attribute inputs that allow you to communicate what each sort does.

  • target: Indicates the name of the sqlfield that will receive the application of the sorting. The following input attributes will get applied to this chosen field.
  • asc: The chosen column will be sorted in ascending order.
  • desc: The chosen column will be sorted in ascending order.
use teil::{Sort, Teil, fields::Serial};

#[derive(Sort)]
enum AccountSort {
    #[teil(target = "owner", asc)]
    ByOwner,
    #[teil(target = "main_balance", desc)]
    ByRichest
}
 
#[derive(Teil)]
#[teil(sort_type = "AccountSort")]
struct Account {
    #[teil(auto, primary_key)]
    id: Serial,
    #[teil(unique)]
    owner: String,
    #[teil(rename = "main_balance")]
    balance: f64
}