Skip to content

Commit

Permalink
collect_functions (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich authored Aug 31, 2023
1 parent d020af6 commit 5181622
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/datatype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ impl Borrow<str> for GenericType {
}
}

impl<'a> From<&'a str> for GenericType {
fn from(value: &'a str) -> Self {
Self(value.to_owned().into())
}
}

impl From<GenericType> for DataType {
fn from(t: GenericType) -> Self {
Self::Generic(t)
Expand Down
10 changes: 4 additions & 6 deletions src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,20 @@ impl_typed_command!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
///
/// fn main() {
/// // `type_defs` is created internally
/// let (functions, type_defs) = functions::collect_types![some_function].unwrap();
/// let (functions, type_defs) = functions::collect_functions![some_function].unwrap();
///
/// let custom_type_defs = TypeMap::default();
///
/// // `type_defs` is provided.
/// // This can be used when integrating multiple specta-enabled libraries.
/// let (functions, custom_type_defs) = functions::collect_types![
/// let (functions, custom_type_defs) = functions::collect_functions![
/// custom_type_defs; // You can provide a custom map to collect the types into
/// some_function
/// ].unwrap();
/// }
/// ````
#[macro_export]
macro_rules! collect_types {
macro_rules! collect_functions {
($type_map:ident; $($command:path),* $(,)?) => {{
let mut type_map: $crate::TypeMap = $type_map;

Expand All @@ -212,8 +212,6 @@ macro_rules! collect_types {
}};
($($command:path),* $(,)?) => {{
let mut type_map = $crate::TypeMap::default();
$crate::functions::collect_types!(type_map; $($command),*)
$crate::functions::collect_functions!(type_map; $($command),*)
}};
}

pub use collect_types;
10 changes: 5 additions & 5 deletions tests/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ mod test {

#[test]
fn test_trailing_comma() {
functions::collect_types![a].unwrap();
functions::collect_types![a,].unwrap();
functions::collect_types![a, b, c].unwrap();
functions::collect_types![a, b, c,].unwrap();
functions::collect_functions![a].unwrap();
functions::collect_functions![a,].unwrap();
functions::collect_functions![a, b, c].unwrap();
functions::collect_functions![a, b, c,].unwrap();

let (functions, types) =
functions::collect_types![a, b, c, d, e::<i32>, f, g, h, i, k].unwrap();
functions::collect_functions![a, b, c, d, e::<i32>, f, g, h, i, k].unwrap();
}

#[test]
Expand Down

0 comments on commit 5181622

Please sign in to comment.