Skip to main content

impl_from_query

Macro impl_from_query 

Source
macro_rules! impl_from_query {
    ($name:ident extends $based:ty { $($field:ident: $col:expr $(=> $mode: ident)?),* $(,)? }) => { ... };
}
Expand description

Helper macro to implement FromQuery for a struct with custom column mappings and optional JSON deserialization.


struct PostPreview {
    id: i64,
    title: String,
    thumb: Option<FileMetaId>,
    updated: i64,
    comments: Vec<Comment>,
}

impl_from_query! {
    PostPreview extends Post {
        id: "id",
        title: "title",
        thumb: "thumb",
        updated: "updated",
        comments: "comments" => json,
    }
}