fix(interface): harden generated public API
This commit is contained in:
@@ -48,6 +48,21 @@
|
||||
//! an application return enum/union and is returned as `Ok(value)`.
|
||||
//! [`HostError`] is reserved for host/runtime failure, so the required
|
||||
//! [`OperationResult`] convention keeps those two failure classes distinct.
|
||||
//!
|
||||
//! # Supported interface syntax
|
||||
//!
|
||||
//! An interface is a public, non-generic trait whose operations use exactly
|
||||
//! `&self`, simple named owned parameters, and an explicit
|
||||
//! `OperationResult<T>`. `WipType` derives support named-field structs,
|
||||
//! all-unit enums, and all-single-payload enums.
|
||||
//!
|
||||
//! The macros reject trait inheritance and associated items; const, async,
|
||||
//! unsafe, extern, variadic, generic, default-bodied, or non-`&self` methods;
|
||||
//! borrowed values and custom lifetimes; tuple, unit, or generic structs;
|
||||
//! mixed or named-field enum variants; explicit discriminants; Rust unions;
|
||||
//! and `Option` anywhere except a direct DTO field or operation parameter.
|
||||
//! Unsupported inputs produce source-located compile errors rather than
|
||||
//! generating a partial interface.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
@@ -619,7 +634,6 @@ pub mod __private {
|
||||
/// Decoder for a protocol record or operation's named argument collection.
|
||||
pub struct RecordDecoder {
|
||||
fields: Vec<NamedValue>,
|
||||
seen: HashSet<String>,
|
||||
}
|
||||
|
||||
impl RecordDecoder {
|
||||
@@ -633,7 +647,7 @@ pub mod __private {
|
||||
.at(field.name.clone()));
|
||||
}
|
||||
}
|
||||
Ok(Self { fields, seen })
|
||||
Ok(Self { fields })
|
||||
}
|
||||
|
||||
/// Decodes a required field.
|
||||
@@ -666,11 +680,5 @@ pub mod __private {
|
||||
let index = self.fields.iter().position(|field| field.name == name)?;
|
||||
Some(self.fields.remove(index).value)
|
||||
}
|
||||
|
||||
/// Returns the set of names supplied to this decoder.
|
||||
#[allow(dead_code)]
|
||||
pub fn supplied_names(&self) -> &HashSet<String> {
|
||||
&self.seen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
use wip_interface::interface;
|
||||
|
||||
#[interface]
|
||||
pub trait AsyncOperation {
|
||||
async fn status(&self) -> wip_interface::OperationResult<String>;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: async operations are not supported
|
||||
--> tests/ui/async_operation.rs:5:5
|
||||
|
|
||||
5 | async fn status(&self) -> wip_interface::OperationResult<String>;
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,10 @@
|
||||
use wip_interface::interface;
|
||||
|
||||
#[interface]
|
||||
pub trait DefaultMethod {
|
||||
fn status(&self) -> wip_interface::OperationResult<String> {
|
||||
Ok(String::new())
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,8 @@
|
||||
error: WIP operation methods must not have a body
|
||||
--> tests/ui/default_method.rs:5:64
|
||||
|
|
||||
5 | fn status(&self) -> wip_interface::OperationResult<String> {
|
||||
| ________________________________________________________________^
|
||||
6 | | Ok(String::new())
|
||||
7 | | }
|
||||
| |_____^
|
||||
@@ -0,0 +1,8 @@
|
||||
use wip_interface::WipType;
|
||||
|
||||
#[derive(WipType)]
|
||||
struct GenericDto<T> {
|
||||
value: T,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: generic DTOs are not supported by `WipType`
|
||||
--> tests/ui/generic_dto.rs:4:18
|
||||
|
|
||||
4 | struct GenericDto<T> {
|
||||
| ^^^
|
||||
@@ -0,0 +1,8 @@
|
||||
use wip_interface::WipType;
|
||||
|
||||
#[derive(WipType)]
|
||||
struct NestedOption {
|
||||
values: Vec<Option<String>>,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `Option<T>` must appear directly as the DTO field type
|
||||
--> tests/ui/nested_option.rs:5:13
|
||||
|
|
||||
5 | values: Vec<Option<String>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user