Simplify admin's RestResourceProvider impls
Simplifies the admin service's `RestResourceProvider` implementations to
be easier to read.
Also adds the `#[allow(unused_mut)]` annotation to one of the resource
definitions for when the `rest-api-actix` feature is not enabled.
@@ -23,19 +23,6 @@ use crate::admin::service::AdminService;
use crate::circuit::store;
use crate::rest_api::{Resource, RestResourceProvider};
-#[cfg(feature = "rest-api-actix")]
-use self::actix::circuits::make_list_circuits_resource;
-#[cfg(feature = "rest-api-actix")]
-use self::actix::circuits_circuit_id::make_fetch_circuit_resource;
-#[cfg(feature = "rest-api-actix")]
-use self::actix::proposals::make_list_proposals_resource;
-#[cfg(feature = "rest-api-actix")]
-use self::actix::proposals_circuit_id::make_fetch_proposal_resource;
-#[cfg(feature = "rest-api-actix")]
-use self::actix::submit::make_submit_route;
-#[cfg(feature = "rest-api-actix")]
-use self::actix::ws_register_type::make_application_handler_registration_route;
-
/// The admin service provides the following endpoints as REST API resources:
///
/// * `GET /ws/admin/register/{type}` - Register as an application authorization handler for the
@@ -50,17 +37,22 @@ use self::actix::ws_register_type::make_application_handler_registration_route;
/// * `rest-api-actix`
impl RestResourceProvider for AdminService {
fn resources(&self) -> Vec<Resource> {
- let mut resources = vec![];
-
- #[cfg(feature = "rest-api-actix")]
- resources.push(make_application_handler_registration_route(self.commands()));
- #[cfg(feature = "rest-api-actix")]
- resources.push(make_submit_route(self.commands()));
+ // Allowing unused_mut because resources must be mutable if feature rest-api-actix is
+ // enabled
+ #[allow(unused_mut)]
+ let mut resources = Vec::new();
#[cfg(feature = "rest-api-actix")]
- resources.push(make_fetch_proposal_resource(self.proposals()));
- #[cfg(feature = "rest-api-actix")]
- resources.push(make_list_proposals_resource(self.proposals()));
+ {
+ resources.append(&mut vec![
+ actix::ws_register_type::make_application_handler_registration_route(
+ self.commands(),
+ ),
+ actix::submit::make_submit_route(self.commands()),
+ actix::proposals_circuit_id::make_fetch_proposal_resource(self.proposals()),
+ actix::proposals::make_list_proposals_resource(self.proposals()),
+ ]);
+ }
resources
}
@@ -105,13 +97,15 @@ impl<T: store::CircuitStore + 'static> RestResourceProvider for CircuitResourceP
// enabled
#[allow(unused_mut)]
let mut resources = Vec::new();
+
#[cfg(feature = "rest-api-actix")]
{
resources.append(&mut vec![
- make_fetch_circuit_resource(self.store.clone()),
- make_list_circuits_resource(self.store.clone()),
- ])
+ actix::circuits_circuit_id::make_fetch_circuit_resource(self.store.clone()),
+ actix::circuits::make_list_circuits_resource(self.store.clone()),
+ ]);
}
+
resources
}
}
