Skip to content

Commit a45e249

Browse files
committed
query: Add pipe! macro
1 parent 21263b5 commit a45e249

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/macros.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,20 @@ macro_rules! pushlen {
4444
$buf.push(b'\n');
4545
}};
4646
}
47+
48+
#[macro_export]
49+
/// The `pipe!` macro is used to create pipelines
50+
///
51+
/// ## Example usage
52+
/// ```
53+
/// use skytable::{pipe, query};
54+
///
55+
/// let pipe = pipe!(query!("sysctl report status"), query!("use $current"));
56+
/// assert_eq!(pipe.query_count(), 2);
57+
/// ```
58+
macro_rules! pipe {
59+
($($query:expr),+) => {{
60+
let mut p = $crate::Pipeline::new();
61+
$(p.push_owned($query);)*p
62+
}}
63+
}

src/query.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ impl Pipeline {
153153
pub fn query_count(&self) -> usize {
154154
self.cnt
155155
}
156+
/// Same as [`Self::push`], but passes ownership to the [`Pipeline`]
157+
pub fn push_owned(&mut self, q: Query) {
158+
self.push(&q);
159+
}
156160
/// Add a query to this pipeline
157161
///
158162
/// Note: It's not possible to get the query back from the pipeline since it's not indexed (and doing so would be an unnecessary

0 commit comments

Comments
 (0)