Skip to content

Commit

Permalink
editoast: move ModelV2 macro np! into utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
leovalais committed Apr 17, 2024
1 parent db4ebae commit 50719a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions editoast/editoast_derive/src/modelv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod codegen;
mod config;
mod identifier;
mod parsing;
mod utils;

use darling::FromDeriveInput as _;
use darling::Result;
Expand Down
19 changes: 1 addition & 18 deletions editoast/editoast_derive/src/modelv2/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
use proc_macro2::{Span, TokenStream};
use quote::quote;

use super::utils::np;
use super::Identifier;
use super::ModelConfig;

/// Nested pair macro
///
/// Helps when using `unzip()` on lot of values.
macro_rules! np {
(vec2) => { np!(Vec<_>, Vec<_>) };
(vec3) => { np!(Vec<_>, Vec<_>, Vec<_>) };
(vec4) => { np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
(vec5) => { np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
(vec6) => { np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
(vec7) => { np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
($id:ident, $($rest:ident),+) => { ($id, np!($($rest),+)) };
($id:ident) => { $id };
($t:ty, $($rest:ty),+) => { ($t, np!($($rest),+)) };
($t:ty) => { $t };
($e:expr, $($rest:expr),+) => { ($e, np!($($rest),+)) };
($e:expr) => { $e };
}

impl ModelConfig {
pub fn make_model_decl(&self, vis: &syn::Visibility) -> TokenStream {
let model = &self.model;
Expand Down
19 changes: 19 additions & 0 deletions editoast/editoast_derive/src/modelv2/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// Nested pair macro
///
/// Helps when using `unzip()` on lot of values.
macro_rules! np {
(vec2) => { $crate::modelv2::utils::np!(Vec<_>, Vec<_>) };
(vec3) => { $crate::modelv2::utils::np!(Vec<_>, Vec<_>, Vec<_>) };
(vec4) => { $crate::modelv2::utils::np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
(vec5) => { $crate::modelv2::utils::np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
(vec6) => { $crate::modelv2::utils::np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
(vec7) => { $crate::modelv2::utils::np!(Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) };
($id:ident, $($rest:ident),+) => { ($id, $crate::modelv2::utils::np!($($rest),+)) };
($id:ident) => { $id };
($t:ty, $($rest:ty),+) => { ($t, $crate::modelv2::utils::np!($($rest),+)) };
($t:ty) => { $t };
($e:expr, $($rest:expr),+) => { ($e, $crate::modelv2::utils::np!($($rest),+)) };
($e:expr) => { $e };
}

pub(crate) use np;

0 comments on commit 50719a5

Please sign in to comment.