From 92e3c4893be679cea1595bdd977d3eac7792f0a5 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 13 Apr 2023 10:21:17 +0200 Subject: [PATCH] wip: Restrict further op --- src/servient.rs | 19 ++++++++++++------- src/servient/builder.rs | 17 ++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/servient.rs b/src/servient.rs index e578539..6b0bde1 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -111,13 +111,18 @@ mod test { let servient = Servient::builder("test") .finish_extend() .property("hello", |b| { - b.finish_extend_data_schema().null().form(|f| { - f.href("/hello") - .http_get(|| async { "Reading Hello, World!" }) - .http_put(|| async { "Writing Hello, World!" }) - .op(FormOperation::ReadProperty) - .op(FormOperation::WriteProperty) - }) + b.finish_extend_data_schema() + .null() + .form(|f| { + f.href("/hello") + .http_get(|| async { "Reading Hello, World!" }) + .op(FormOperation::ReadProperty) + }) + .form(|f| { + f.href("/hello") + .http_put(|| async { "Writing Hello, World!" }) + .op(FormOperation::WriteProperty) + }) }) .build_servient() .unwrap(); diff --git a/src/servient/builder.rs b/src/servient/builder.rs index e77f6a7..70e2f30 100644 --- a/src/servient/builder.rs +++ b/src/servient/builder.rs @@ -12,7 +12,7 @@ use datta::{Operator, UriTemplate}; use serde::{Deserialize, Serialize}; use uuid::Uuid; use wot_td::{ - builder::{FormBuilderInner, ThingBuilder, CAN_ADD_ANY_OPS}, + builder::{FormBuilder, ThingBuilder, CAN_ADD_ANY_OPS, CAN_ADD_ONE_OP}, extend::ExtendableThing, protocol::http, }; @@ -267,13 +267,12 @@ pub trait HttpRouter { T: 'static; } -impl HttpRouter - for FormBuilderInner +impl HttpRouter for FormBuilder where Other: ExtendableThing + Holder, OtherForm: Holder
, { - type Target = FormBuilderInner; + type Target = FormBuilder; /// Route GET requests to the given handler. fn http_get(mut self, handler: H) -> Self::Target @@ -285,7 +284,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.get(handler); f.htv.method_name = Some(http::Method::Get); - self + self.into() } /// Route PUT requests to the given handler. fn http_put(mut self, handler: H) -> Self::Target @@ -297,7 +296,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.put(handler); f.htv.method_name = Some(http::Method::Put); - self + self.into() } /// Route POST requests to the given handler. fn http_post(mut self, handler: H) -> Self::Target @@ -309,7 +308,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.post(handler); f.htv.method_name = Some(http::Method::Post); - self + self.into() } /// Route PATCH requests to the given handler. fn http_patch(mut self, handler: H) -> Self::Target @@ -321,7 +320,7 @@ where let f: &mut Form = self.other.field_mut(); f.method_router = method_router.patch(handler); f.htv.method_name = Some(http::Method::Patch); - self + self.into() } /// Route DELETE requests to the given handler. fn http_delete(mut self, handler: H) -> Self::Target @@ -333,7 +332,7 @@ where let f: &mut Form = self.other.field_mut(); f.method_router = method_router.delete(handler); f.htv.method_name = Some(http::Method::Delete); - self + self.into() } }