1 use crate::api_schema
::router
::*;
3 use std
::collections
::HashMap
;
4 use std
::path
::{PathBuf}
;
10 router
: &'
static Router
,
11 aliases
: HashMap
<String
, PathBuf
>,
12 env_type
: RpcEnvironmentType
,
17 pub fn new
<B
: Into
<PathBuf
>>(basedir
: B
, router
: &'
static Router
, env_type
: RpcEnvironmentType
) -> Self {
19 basedir
: basedir
.into(),
21 aliases
: HashMap
::new(),
30 uri_param
: &mut HashMap
<String
, String
>,
31 ) -> Option
<&'
static ApiMethod
> {
33 self.router
.find_method(components
, method
, uri_param
)
36 pub fn find_alias(&self, components
: &[&str]) -> PathBuf
{
38 let mut prefix
= String
::new();
39 let mut filename
= self.basedir
.clone();
40 let comp_len
= components
.len();
42 prefix
.push_str(components
[0]);
43 if let Some(subdir
) = self.aliases
.get(&prefix
) {
44 filename
.push(subdir
);
45 for i
in 1..comp_len { filename.push(components[i]) }
47 for i
in 0..comp_len { filename.push(components[i]) }
53 pub fn add_alias
<S
, P
>(&mut self, alias
: S
, path
: P
)
54 where S
: Into
<String
>,
57 self.aliases
.insert(alias
.into(), path
.into());
60 pub fn env_type(&self) -> RpcEnvironmentType
{