Skip to content

Commit

Permalink
Allow associated types in #[conjure_endpoints]
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Jan 7, 2024
1 parent bdc45f4 commit 7d83144
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
version = "3.6.0"

[workspace]
resolver = "2"
members = [
"conjure-codegen",
"conjure-error",
Expand Down
15 changes: 6 additions & 9 deletions conjure-macros/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,11 @@ impl Service {

let mut endpoints = vec![];
for item in &trait_.items {
match Endpoint::new(item) {
let TraitItem::Fn(item_fn) = item else {
continue;
};

match Endpoint::new(item_fn) {
Ok(endpoint) => endpoints.push(endpoint),
Err(e) => {
errors.push(e);
Expand Down Expand Up @@ -666,14 +670,7 @@ struct Endpoint {
}

impl Endpoint {
fn new(item: &TraitItem) -> Result<Self, Error> {
let TraitItem::Fn(item) = item else {
return Err(Error::new_spanned(
item,
"Conjure traits may only contain methods",
));
};

fn new(item: &TraitItemFn) -> Result<Self, Error> {
let mut errors = Errors::new();

let mut endpoint_attrs = item
Expand Down
6 changes: 5 additions & 1 deletion conjure-test/src/test/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,14 +948,16 @@ trait CustomStreamingService<#[request_body] I, #[response_writer] O>
where
O: Write,
{
type StreamingResponseBody: WriteBody<O> + 'static + Send;

#[endpoint(method = POST, path = "/test/stremaingRequest")]
fn streaming_request(
&self,
#[body(deserializer = RawRequestDeserializer)] body: I,
) -> Result<(), Error>;

#[endpoint(method = GET, path = "/test/streamingReponse", produces = RawResponseSerializer)]
fn streaming_response(&self) -> Result<TestBodyWriter, Error>;
fn streaming_response(&self) -> Result<Self::StreamingResponseBody, Error>;
}

// We can't annotate the trait with #[mockall] due to annoying interactions with #[conjure_endpoints]
Expand All @@ -966,6 +968,8 @@ mock! {
where
O: Write
{
type StreamingResponseBody = TestBodyWriter;

fn streaming_request(&self, body: I) -> Result<(), Error>;
fn streaming_response(&self) -> Result<TestBodyWriter, Error>;
}
Expand Down

0 comments on commit 7d83144

Please sign in to comment.