Use toplevel imports in ruma_api! expansion
This commit is contained in:
parent
c39e9f5779
commit
0366466792
@ -247,14 +247,6 @@ impl ToTokens for Api {
|
||||
};
|
||||
|
||||
let api = quote! {
|
||||
// FIXME: These can't conflict with other imports, but it would still be nice not to
|
||||
// bring anything into scope that code outside the macro could then rely on.
|
||||
use ::std::convert::TryInto as _;
|
||||
|
||||
use ::ruma_api::exports::serde::de::Error as _;
|
||||
use ::ruma_api::exports::serde::Deserialize as _;
|
||||
use ::ruma_api::Endpoint as _;
|
||||
|
||||
#[doc = #request_doc]
|
||||
#request_type
|
||||
|
||||
|
@ -61,21 +61,24 @@ impl Request {
|
||||
let header_name_string = header_name.to_string();
|
||||
|
||||
quote! {
|
||||
#field_name: match headers.get(::ruma_api::exports::http::header::#header_name)
|
||||
.and_then(|v| v.to_str().ok()) {
|
||||
Some(header) => header.to_owned(),
|
||||
None => {
|
||||
return Err(
|
||||
::ruma_api::error::RequestDeserializationError::new(
|
||||
::ruma_api::exports::serde_json::Error::missing_field(
|
||||
#header_name_string
|
||||
),
|
||||
request,
|
||||
)
|
||||
.into()
|
||||
);
|
||||
}
|
||||
#field_name: match headers
|
||||
.get(::ruma_api::exports::http::header::#header_name)
|
||||
.and_then(|v| v.to_str().ok()) // FIXME: Should have a distinct error message
|
||||
{
|
||||
Some(header) => header.to_owned(),
|
||||
None => {
|
||||
use ::ruma_api::exports::serde::de::Error as _;
|
||||
|
||||
// FIXME: Not a missing json field, a missing header!
|
||||
return Err(::ruma_api::error::RequestDeserializationError::new(
|
||||
::ruma_api::exports::serde_json::Error::missing_field(
|
||||
#header_name_string
|
||||
),
|
||||
request,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma_api::{ruma_api, Endpoint as _};
|
||||
use ruma_identifiers::{user_id, UserId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -36,10 +38,6 @@ ruma_api! {
|
||||
|
||||
#[test]
|
||||
fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma_identifiers::user_id;
|
||||
|
||||
let req = Request {
|
||||
hello: "hi".to_owned(),
|
||||
world: "test".to_owned(),
|
||||
|
@ -5,7 +5,7 @@ use std::fmt;
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use serde::{
|
||||
de::{MapAccess, Visitor},
|
||||
de::{Error as _, MapAccess, Visitor},
|
||||
ser::SerializeStruct,
|
||||
Deserialize, Deserializer, Serialize, Serializer,
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||
use serde::{
|
||||
de::{MapAccess, Visitor},
|
||||
de::{Error as _, MapAccess, Visitor},
|
||||
ser::SerializeStruct,
|
||||
Deserialize, Deserializer, Serialize, Serializer,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user