changeset 11: |
d8f806f1d327 |
parent: |
315fedf35bc7
|
author: |
ellis <ellis@rwest.io> |
date: |
Sun, 14 May 2023 21:27:04 -0400 |
permissions: |
-rw-r--r-- |
description: |
obj updates |
1 //! obj/src/types.rs --- OBJ type descriptions used by our demo 2 use crate::{Deserialize, Objective, Result, Serialize}; 3 use std::collections::HashMap; 6 #[derive(Serialize,Deserialize,Default)] 10 Dynamic(Vec<Service>), 11 Custom(CustomService), 16 impl Objective for Service {} 18 impl From<&str> for Service { 19 fn from(value: &str) -> Self { 21 "weather" => Service::Weather, 22 "stocks" => Service::Stocks, 23 "bench" => Service::Bench, 28 x.map(|y| Service::Custom(y.into())) 29 .collect::<Vec<Service>>(), 32 Service::Custom(s.into()) 39 #[derive(Serialize,Deserialize,Default)] 40 pub struct CustomService { 42 registry: HashMap<String,Vec<u8>>, 45 impl Objective for CustomService {} 46 impl From<CustomService> for Service { 47 fn from(value: CustomService) -> Self { 48 Service::Custom(value) 51 impl From<&str> for CustomService { 52 fn from(value: &str) -> Self { 53 let name = value.to_owned(); 54 let registry = HashMap::new(); 55 CustomService { name, registry } 59 #[derive(Serialize, Deserialize,Default)] 60 pub struct Complex<X: Objective> { 63 registry: HashMap<String,Vec<u8>>, 66 impl Objective for Complex<Service> {} 68 pub fn generate_complex() -> Result<Complex<Service>> { 69 Ok(Complex::<Service>::from_json_str("hi")?)