derive_sql/selectable/
simplelimit.rs1use super::*;
2
3pub struct SimpleLimit {
4 limit: Option<usize>,
5 next: Option<Box<dyn Selectable>>,
6}
7
8impl SimpleLimit {
9 pub fn and(mut self, next: Box<dyn Selectable>) -> SimpleLimit { self.next = Some(next); self }
10}
11
12impl Selectable for SimpleLimit {
13 fn filter(&self) -> Option<String> { self.next.as_ref().and_then(|n| n.filter()) }
14 fn limit(&self) -> Option<usize> { self.limit.as_ref().cloned() }
15 fn offset(&self) -> Option<usize> { self.next.as_ref().and_then(|n| n.offset()) }
16 fn order_by(&self) -> Option<String> { self.next.as_ref().and_then(|n| n.order_by()) }
17}
18
19impl std::convert::TryFrom<()> for SimpleLimit {
20 type Error = Box<dyn std::error::Error>;
21 fn try_from(_: ()) -> std::result::Result<Self, Self::Error> {
22 Ok(SimpleLimit { limit: None, next: None })
23 }
24}
25
26impl std::convert::TryFrom<usize> for SimpleLimit {
27 type Error = Box<dyn std::error::Error>;
28 fn try_from(v: usize) -> std::result::Result<Self, Self::Error> {
29 Ok(SimpleLimit { limit: Some(v), next: None})
30 }
31}
32