Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity-1686a committed Aug 13, 2019
1 parent 12a952f commit d225170
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
31 changes: 15 additions & 16 deletions plume-models/src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ struct NewList<'a> {
type_: i32,
}


macro_rules! func {
(@elem User $id:expr, $value:expr) => {
NewListElem {
Expand Down Expand Up @@ -186,7 +185,11 @@ impl List {
}
}

pub fn find_for_user_by_name(conn: &Connection, user_id: Option<i32>, name: &str) -> Result<Self> {
pub fn find_for_user_by_name(
conn: &Connection,
user_id: Option<i32>,
name: &str,
) -> Result<Self> {
if let Some(user_id) = user_id {
lists::table
.filter(lists::user_id.eq(user_id))
Expand Down Expand Up @@ -242,27 +245,23 @@ impl List {
private::ListElem::prefix_in_list(conn, self, word)
}



/// Insert new users in a list
func!{add: add_users, User}
func! {add: add_users, User}

/// Insert new blogs in a list
func!{add: add_blogs, Blog}
func! {add: add_blogs, Blog}

/// Insert new words in a list
func!{add: add_words, Word}
func! {add: add_words, Word}

/// Insert new prefixes in a list
func!{add: add_prefixes, Prefix}

func! {add: add_prefixes, Prefix}

/// Get all users in the list
func!{list: list_users, User, users}

func! {list: list_users, User, users}

/// Get all blogs in the list
func!{list: list_blogs, Blog, blogs}
func! {list: list_blogs, Blog, blogs}

/// Get all words in the list
pub fn list_words(&self, conn: &Connection) -> Result<Vec<String>> {
Expand Down Expand Up @@ -295,10 +294,10 @@ impl List {
.map_err(Error::from)
}

func!{set: set_users, User, add_users}
func!{set: set_blogs, Blog, add_blogs}
func!{set: set_words, Word, add_words}
func!{set: set_prefixes, Prefix, add_prefixes}
func! {set: set_users, User, add_users}
func! {set: set_blogs, Blog, add_blogs}
func! {set: set_words, Word, add_words}
func! {set: set_prefixes, Prefix, add_prefixes}
}

mod private {
Expand Down
12 changes: 9 additions & 3 deletions plume-models/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ impl Timeline {
insert!(timeline_definition, NewTimeline);
get!(timeline_definition);

pub fn find_for_user_by_name(conn: &Connection, user_id: Option<i32>, name: &str) -> Result<Self> {
pub fn find_for_user_by_name(
conn: &Connection,
user_id: Option<i32>,
name: &str,
) -> Result<Self> {
if let Some(user_id) = user_id {
timeline_definition::table
.filter(timeline_definition::user_id.eq(user_id))
Expand Down Expand Up @@ -140,7 +144,8 @@ impl Timeline {
.list_used_lists()
.into_iter()
.find_map(|(name, kind)| {
let list = List::find_for_user_by_name(conn, None, &name).map(|l| l.kind() == kind);
let list = List::find_for_user_by_name(conn, None, &name)
.map(|l| l.kind() == kind);
match list {
Ok(true) => None,
Ok(false) => Some(Error::TimelineQuery(QueryError::RuntimeError(
Expand Down Expand Up @@ -284,7 +289,8 @@ mod tests {
assert_eq!(tl1_u1, Timeline::get(conn, tl1_u1.id).unwrap());
assert_eq!(
tl2_u1,
Timeline::find_for_user_by_name(conn, Some(users[0].id), "another timeline").unwrap()
Timeline::find_for_user_by_name(conn, Some(users[0].id), "another timeline")
.unwrap()
);
assert_eq!(
tl1_instance,
Expand Down
3 changes: 2 additions & 1 deletion plume-models/src/timeline/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ impl WithList {
) -> Result<bool> {
match list {
List::List(name) => {
let list = lists::List::find_for_user_by_name(&rocket.conn, timeline.user_id, &name)?;
let list =
lists::List::find_for_user_by_name(&rocket.conn, timeline.user_id, &name)?;
match (self, list.kind()) {
(WithList::Blog, ListType::Blog) => {
list.contains_blog(&rocket.conn, post.blog_id)
Expand Down

0 comments on commit d225170

Please sign in to comment.