refactor code to use Shrinkwraprs and diesel-derive-newtype (#598)
* add shrinkwraprs and implement Id thru it This also means we can automatically convert Id to String without using .into()! * cleanup with the help of clippy! * cleanup with the help of cargo fmt! * remove extra block * Shrinkwrap Page, ContentLen and RemoteForm * translations
This commit is contained in:
committed by
Baptiste Gelez
parent
59023e9602
commit
8c59c822b6
@@ -62,6 +62,8 @@ mod mail;
|
||||
#[macro_use]
|
||||
mod template_utils;
|
||||
mod routes;
|
||||
#[macro_use]
|
||||
extern crate shrinkwraprs;
|
||||
#[cfg(feature = "test")]
|
||||
mod test_routes;
|
||||
|
||||
|
||||
+3
-2
@@ -16,7 +16,7 @@ use plume_models::{posts::Post, Connection};
|
||||
|
||||
const ITEMS_PER_PAGE: i32 = 12;
|
||||
|
||||
#[derive(Copy, Clone, UriDisplayQuery)]
|
||||
#[derive(Shrinkwrap, Copy, Clone, UriDisplayQuery)]
|
||||
pub struct Page(i32);
|
||||
|
||||
impl<'v> FromFormValue<'v> for Page {
|
||||
@@ -52,6 +52,7 @@ impl Page {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Shrinkwrap)]
|
||||
pub struct ContentLen(pub u64);
|
||||
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for ContentLen {
|
||||
@@ -72,7 +73,7 @@ impl Default for Page {
|
||||
}
|
||||
|
||||
/// A form for remote interaction, used by multiple routes
|
||||
#[derive(Clone, Default, FromForm)]
|
||||
#[derive(Shrinkwrap, Clone, Default, FromForm)]
|
||||
pub struct RemoteForm {
|
||||
pub remote: String,
|
||||
}
|
||||
|
||||
+1
-2
@@ -193,8 +193,7 @@ pub fn follow_not_connected(
|
||||
) -> Result<Result<Flash<Ructe>, Redirect>, ErrorPage> {
|
||||
let target = User::find_by_fqn(&rockets, &name)?;
|
||||
if let Some(remote_form) = remote_form {
|
||||
let remote = &remote_form.remote;
|
||||
if let Some(uri) = User::fetch_remote_interact_uri(remote)
|
||||
if let Some(uri) = User::fetch_remote_interact_uri(&remote_form)
|
||||
.ok()
|
||||
.and_then(|uri| {
|
||||
rt_format!(
|
||||
|
||||
Reference in New Issue
Block a user