changeset 7: |
315fedf35bc7 |
parent: |
8f59e2f1b8c4
|
child: |
d8f806f1d327 |
author: |
ellis <ellis@rwest.io> |
date: |
Sun, 07 May 2023 18:06:13 -0400 |
permissions: |
-rw-r--r-- |
description: |
rust ffi macros, general stuff |
1 //! obj/src/types.rs --- OBJ type descriptions used by our demo 2 use crate::{Deserialize, Objective, Result, Serialize}; 4 #[derive(Serialize, Deserialize)] 13 impl Objective for Service {} 15 impl From<&str> for Service { 16 fn from(value: &str) -> Self { 18 "weather" => Service::Weather, 19 "stocks" => Service::Stocks, 20 "test" => Service::Test, 25 x.map(|y| Service::Custom(y.into())) 26 .collect::<Vec<Service>>(), 29 Service::Custom(s.into()) 36 #[derive(Serialize, Deserialize)] 37 pub struct CustomService { 40 impl Objective for CustomService {} 41 impl From<CustomService> for Service { 42 fn from(value: CustomService) -> Self { 43 Service::Custom(value) 46 impl From<&str> for CustomService { 47 fn from(value: &str) -> Self { 48 let name = value.to_owned(); 49 CustomService { name } 53 #[derive(Serialize, Deserialize)] 54 pub struct Complex<X: Objective> { 59 impl Objective for Complex<Service> {} 61 pub fn generate_complex() -> Result<Complex<Service>> { 62 Ok(Complex::<Service>::from_json_str("hi")?)