move impl closer to mother struct

This commit is contained in:
Igor Galić 2019-05-27 17:53:10 +02:00 committed by Igor Galić
parent b09b51c74b
commit f94b0c79c5
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86

View File

@ -53,6 +53,24 @@ impl AsRef<str> for Host {
}
}
impl<'a, 'r> FromRequest<'a, 'r> for Host {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<Host, ()> {
request
.headers()
.get_one("Host")
.and_then(|x| {
if Blog::list_custom_domains().contains(&x.to_string()) {
Some(Host::new(x))
} else {
None
}
})
.or_forward(())
}
}
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
#[changeset_options(treat_none_as_null = "true")]
pub struct Blog {
@ -342,24 +360,6 @@ impl Blog {
}
}
impl<'a, 'r> FromRequest<'a, 'r> for Host {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<Host, ()> {
request
.headers()
.get_one("Host")
.and_then(|x| {
if Blog::list_custom_domains().contains(&x.to_string()) {
Some(Host::new(x))
} else {
None
}
})
.or_forward(())
}
}
impl IntoId for Blog {
fn into_id(self) -> Id {
Id::new(self.ap_url)