sausage-plugin part 1: run, #[rpc], #[schema], rpc.discover, calls, locks, Ctx, hooks
Checkpoint. Known issues, fixed in part 2: short writes on stdout, byte-wise stdin reads, Result suffix on all result schemas, lost enum variant docs, serde errors as invalid params, missing item docs.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
//! Reject data-carrying enums.
|
||||
/// An invalid enum.
|
||||
#[sausage_plugin::schema]
|
||||
enum Bad {
|
||||
/// A payload variant.
|
||||
Value(String),
|
||||
}
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: schema enums require unit variants
|
||||
--> tests/ui/enum.rs:5:5
|
||||
|
|
||||
5 | /// A payload variant.
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1,5 @@
|
||||
//! Require field documentation.
|
||||
/// A documented type.
|
||||
#[sausage_plugin::schema]
|
||||
struct Bad { value: String }
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: a doc comment is required
|
||||
--> tests/ui/field_docs.rs:4:14
|
||||
|
|
||||
4 | struct Bad { value: String }
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,5 @@
|
||||
//! Require method documentation.
|
||||
struct Bad;
|
||||
#[sausage_plugin::rpc]
|
||||
impl Bad { fn bad(&self)->sausage_plugin::Result<()> {Ok(())} }
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: a doc comment is required
|
||||
--> tests/ui/method_docs.rs:4:12
|
||||
|
|
||||
4 | impl Bad { fn bad(&self)->sausage_plugin::Result<()> {Ok(())} }
|
||||
| ^^
|
||||
@@ -0,0 +1,4 @@
|
||||
//! Reject undocumented schemas.
|
||||
#[sausage_plugin::schema]
|
||||
struct Bad { value: String }
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: a doc comment is required
|
||||
--> tests/ui/missing_docs.rs:3:8
|
||||
|
|
||||
3 | struct Bad { value: String }
|
||||
| ^^^
|
||||
@@ -0,0 +1,8 @@
|
||||
//! Reject primitive params.
|
||||
struct Bad;
|
||||
#[sausage_plugin::rpc]
|
||||
impl Bad {
|
||||
/// Invalid params.
|
||||
fn bad(&self, value:String)->sausage_plugin::Result<String> {Ok(value)}
|
||||
}
|
||||
fn main() {}
|
||||
@@ -0,0 +1,34 @@
|
||||
error[E0277]: RPC params must be a #[schema] struct with named fields
|
||||
--> tests/ui/params.rs:6:25
|
||||
|
|
||||
6 | fn bad(&self, value:String)->sausage_plugin::Result<String> {Ok(value)}
|
||||
| ^^^^^^ the trait `Params` is not implemented for `std::string::String`
|
||||
|
|
||||
help: the trait `Params` is implemented for `sausage_plugin::Empty`
|
||||
--> src/lib.rs
|
||||
|
|
||||
| impl Params for Empty {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
note: required by a bound in `method`
|
||||
--> src/lib.rs
|
||||
|
|
||||
| pub fn method<P: Params, R: SchemaType>(doc: &mut Value, name: &str, docs: &str) {
|
||||
| ^^^^^^ required by this bound in `method`
|
||||
|
||||
error[E0277]: RPC params must be a #[schema] struct with named fields
|
||||
--> tests/ui/params.rs:6:25
|
||||
|
|
||||
6 | fn bad(&self, value:String)->sausage_plugin::Result<String> {Ok(value)}
|
||||
| ^^^^^^ the trait `Params` is not implemented for `std::string::String`
|
||||
|
|
||||
help: the trait `Params` is implemented for `sausage_plugin::Empty`
|
||||
--> src/lib.rs
|
||||
|
|
||||
| impl Params for Empty {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
note: required by a bound in `params_type`
|
||||
--> tests/ui/params.rs:3:1
|
||||
|
|
||||
3 | #[sausage_plugin::rpc]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `params_type`
|
||||
= note: this error originates in the attribute macro `sausage_plugin::rpc` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,9 @@
|
||||
//! Reject serde shapes outside the subset.
|
||||
/// A schema with flatten.
|
||||
#[sausage_plugin::schema]
|
||||
struct Bad {
|
||||
/// A flattened value.
|
||||
#[serde(flatten)]
|
||||
value: String,
|
||||
}
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: serde attribute is outside the schema subset
|
||||
--> tests/ui/serde.rs:6:13
|
||||
|
|
||||
6 | #[serde(flatten)]
|
||||
| ^^^^^^^
|
||||
@@ -0,0 +1,8 @@
|
||||
//! Reject invalid receiver signatures.
|
||||
struct Bad;
|
||||
#[sausage_plugin::rpc]
|
||||
impl Bad {
|
||||
/// An invalid receiver.
|
||||
fn bad(&mut self) -> sausage_plugin::Result<()> {Ok(())}
|
||||
}
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: RPC methods require &self
|
||||
--> tests/ui/signature.rs:6:5
|
||||
|
|
||||
6 | fn bad(&mut self) -> sausage_plugin::Result<()> {Ok(())}
|
||||
| ^^
|
||||
@@ -0,0 +1,8 @@
|
||||
//! Reject unsupported field types.
|
||||
/// An invalid schema.
|
||||
#[sausage_plugin::schema]
|
||||
struct Bad {
|
||||
/// An unsupported dictionary.
|
||||
value: std::collections::HashMap<String,String>,
|
||||
}
|
||||
fn main() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
error[E0277]: this type is outside the Sausage schema subset
|
||||
--> tests/ui/subset.rs:6:12
|
||||
|
|
||||
6 | value: std::collections::HashMap<String,String>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SchemaType` is not implemented for `HashMap<std::string::String, std::string::String>`
|
||||
|
|
||||
= help: the following other types implement trait `SchemaType`:
|
||||
()
|
||||
Bad
|
||||
Vec<T>
|
||||
bool
|
||||
f32
|
||||
f64
|
||||
i16
|
||||
i32
|
||||
and $N others
|
||||
note: required by a bound in `supported`
|
||||
--> tests/ui/subset.rs:3:1
|
||||
|
|
||||
3 | #[sausage_plugin::schema]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `supported`
|
||||
= note: this error originates in the attribute macro `sausage_plugin::schema` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,5 @@
|
||||
//! Reject tuple params.
|
||||
/// A tuple is not a named object.
|
||||
#[sausage_plugin::schema]
|
||||
struct Bad(String);
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: schema structs require named fields
|
||||
--> tests/ui/tuple.rs:2:1
|
||||
|
|
||||
2 | /// A tuple is not a named object.
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user