feat(interface): add authoring macros and codecs

Add the wip-interface facade and proc-macro implementation for typed interface descriptors, DTO value codecs, validated dispatch, metadata extraction, and span-aware compile failures.
This commit is contained in:
2026-09-28 23:11:17 +09:00
parent 6b6e96c303
commit 18ac8844b0
32 changed files with 2991 additions and 1 deletions
@@ -0,0 +1,10 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait AssociatedType {
type Item;
fn load(&self) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,13 @@
error: associated types are not supported in WIP interfaces
--> tests/ui/associated_type.rs:5:5
|
5 | type Item;
| ^^^^^^^^^^
warning: unused import: `OperationResult`
--> tests/ui/associated_type.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,8 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait BadReceiver {
fn load(&mut self) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,13 @@
error: the only supported receiver is exactly `&self`
--> tests/ui/bad_receiver.rs:5:13
|
5 | fn load(&mut self) -> OperationResult<String>;
| ^^^^^^^^^
warning: unused import: `OperationResult`
--> tests/ui/bad_receiver.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,8 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait BadReturn {
fn load(&self) -> String;
}
fn main() {}
@@ -0,0 +1,13 @@
error: an operation must explicitly return `OperationResult<T>`
--> tests/ui/bad_return.rs:5:23
|
5 | fn load(&self) -> String;
| ^^^^^^
warning: unused import: `OperationResult`
--> tests/ui/bad_return.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,8 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait BorrowedValue<'a> {
fn load(&self, value: &'a str) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,13 @@
error: generic WIP interface traits are not supported
--> tests/ui/custom_lifetime.rs:4:24
|
4 | pub trait BorrowedValue<'a> {
| ^^^^
warning: unused import: `OperationResult`
--> tests/ui/custom_lifetime.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,9 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait DuplicateOperation {
fn load(&self) -> OperationResult<String>;
fn load(&self, other: String) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,13 @@
error: duplicate operation name `load`
--> tests/ui/duplicate_operation.rs:6:8
|
6 | fn load(&self, other: String) -> OperationResult<String>;
| ^^^^
warning: unused import: `OperationResult`
--> tests/ui/duplicate_operation.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,8 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait GenericOperation {
fn load<T>(&self, value: T) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,13 @@
error: generic operations are not supported
--> tests/ui/generic_method.rs:5:12
|
5 | fn load<T>(&self, value: T) -> OperationResult<String>;
| ^^^
warning: unused import: `OperationResult`
--> tests/ui/generic_method.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,8 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait Inherited: Send {
fn load(&self) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,13 @@
error: WIP interface trait inheritance is not supported
--> tests/ui/inherited_trait.rs:4:22
|
4 | pub trait Inherited: Send {
| ^^^^
warning: unused import: `OperationResult`
--> tests/ui/inherited_trait.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,9 @@
use wip_interface::WipType;
#[derive(WipType)]
enum MixedEnum {
Empty,
Payload(String),
}
fn main() {}
@@ -0,0 +1,5 @@
error: a `WipType` enum must contain either only unit variants or only single-field tuple variants; mixed and named-field variants are unsupported
--> tests/ui/mixed_enum.rs:4:1
|
4 | enum MixedEnum {
| ^^^^
@@ -0,0 +1,8 @@
use wip_interface::{OperationResult, interface};
#[interface]
trait PrivateInterface {
fn load(&self) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,15 @@
error: a WIP interface trait must be public
--> tests/ui/private_trait.rs:3:1
|
3 | #[interface]
| ^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `interface` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: unused import: `OperationResult`
--> tests/ui/private_trait.rs:1:21
|
1 | use wip_interface::{OperationResult, interface};
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
@@ -0,0 +1,6 @@
use wip_interface::WipType;
#[derive(WipType)]
struct TupleDto(String, String);
fn main() {}
@@ -0,0 +1,5 @@
error: `WipType` supports only structs with named fields
--> tests/ui/tuple_dto.rs:4:16
|
4 | struct TupleDto(String, String);
| ^^^^^^^^^^^^^^^^
@@ -0,0 +1,8 @@
use wip_interface::{OperationResult, interface};
#[interface]
pub trait UnsupportedType {
fn load(&self, pair: (String, String)) -> OperationResult<String>;
}
fn main() {}
@@ -0,0 +1,41 @@
error[E0277]: the trait bound `(std::string::String, std::string::String): WipType` is not satisfied
--> tests/ui/unsupported_type.rs:5:26
|
5 | fn load(&self, pair: (String, String)) -> OperationResult<String>;
| ^^^^^^^^^^^^^^^^ the trait `WipType` is not implemented for `(std::string::String, std::string::String)`
|
= help: the following other types implement trait `WipType`:
JsonValue
Vec<T>
bool
f32
f64
i128
i16
i32
and $N others
error[E0277]: the trait bound `(std::string::String, std::string::String): WipType` is not satisfied
--> tests/ui/unsupported_type.rs:5:26
|
3 | #[interface]
| ------------ required by a bound introduced by this call
4 | pub trait UnsupportedType {
5 | fn load(&self, pair: (String, String)) -> OperationResult<String>;
| ^^^^^^^^^^^^^^^^ the trait `WipType` is not implemented for `(std::string::String, std::string::String)`
|
= help: the following other types implement trait `WipType`:
JsonValue
Vec<T>
bool
f32
f64
i128
i16
i32
and $N others
note: required by a bound in `wip_interface::__private::RecordDecoder::required`
--> src/lib.rs
|
| pub fn required<T: WipType>(&mut self, name: &str) -> Result<T, CodecError> {
| ^^^^^^^ required by this bound in `RecordDecoder::required`