Skip to main content

fcpv2/types/
traits.rs

1
2pub trait FcpRequest {
3    fn convert(&self) -> String;
4    fn fcp_wrap(&self, prefix: &str, postfix: &str) -> String {
5        format!("{}{}{}", prefix, self.convert(), postfix)
6    }
7}
8
9
10pub trait FcpParser<T> {
11    fn parse(palin: &str) -> Option<T>;
12}
13
14pub fn fcp_types_unwrap<T: FcpRequest>(fcp_type: Option<&T>) -> String {
15    match fcp_type {
16        Some(val) => val.convert(),
17        None => String::from(""),
18    }
19}
20pub fn to_fcp_unwrap<T: FcpRequest>(prefix: &str, fcp_type: &Option<T>, postfix: &str) -> String {
21    match fcp_type {
22        Some(val) => val.fcp_wrap(&prefix, &postfix),
23        None => String::from(""),
24    }
25}
26
27