1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use super::*;

pub struct SimpleLimit {
  limit: Option<usize>,
  next: Option<Box<dyn Selectable>>,
}

impl SimpleLimit {
  pub fn and(mut self, next: Box<dyn Selectable>) -> SimpleLimit { self.next = Some(next); self }
}

impl Selectable for SimpleLimit {
  fn filter(&self) -> Option<String> { self.next.as_ref().and_then(|n| n.filter()) }
  fn limit(&self) -> Option<usize> { self.limit.as_ref().cloned() }
  fn offset(&self) -> Option<usize> { self.next.as_ref().and_then(|n| n.offset()) }
  fn order_by(&self) -> Option<String> { self.next.as_ref().and_then(|n| n.order_by()) }
}

impl std::convert::TryFrom<()> for SimpleLimit {
  type Error = Box<dyn std::error::Error>;
  fn try_from(_: ()) -> Result<Self, Self::Error> {
    Ok(SimpleLimit { limit: None, next: None })
  }
}

impl std::convert::TryFrom<usize> for SimpleLimit {
  type Error = Box<dyn std::error::Error>;
  fn try_from(v: usize) -> Result<Self, Self::Error> {
    Ok(SimpleLimit { limit: Some(v), next: None})
  }
}