-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-classmapper.rs
More file actions
46 lines (40 loc) · 1.24 KB
/
example-classmapper.rs
File metadata and controls
46 lines (40 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Serialize, Deserialize)]
enum FrameworkType {
AspNet,
Django,
Angular,
// ... other frameworks
}
#[derive(Serialize, Deserialize)]
struct RequestData {
end_type: String,
name: String,
// ... other fields
}
fn framework_factory(request_data: &RequestData) -> Result<Box<dyn FrameworkConfig>, String> {
match request_data.name.as_str() {
"aspnet-core" => {
// Deserialize into AspNetConfig and return
// serde_json::from_value::<AspNetConfig>(...)
},
"django" => {
// Deserialize into DjangoConfig and return
// serde_json::from_value::<DjangoConfig>(...)
},
"angular" => {
// Deserialize into AngularConfig and return
// serde_json::from_value::<AngularConfig>(...)
},
// ... other frameworks
_ => Err("Unsupported framework".to_string()),
}
}
trait FrameworkConfig {
// Define common behavior for all framework configs...
}
impl FrameworkConfig for AspNetConfig { /* ... */ }
impl FrameworkConfig for DjangoConfig { /* ... */ }
impl FrameworkConfig for AngularConfig { /* ... */ }
// ... Rest of the struct definitions