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! {
|
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]
|
#[doc = #request_doc]
|
||||||
#request_type
|
#request_type
|
||||||
|
|
||||||
|
@ -61,19 +61,22 @@ impl Request {
|
|||||||
let header_name_string = header_name.to_string();
|
let header_name_string = header_name.to_string();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#field_name: match headers.get(::ruma_api::exports::http::header::#header_name)
|
#field_name: match headers
|
||||||
.and_then(|v| v.to_str().ok()) {
|
.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(),
|
Some(header) => header.to_owned(),
|
||||||
None => {
|
None => {
|
||||||
return Err(
|
use ::ruma_api::exports::serde::de::Error as _;
|
||||||
::ruma_api::error::RequestDeserializationError::new(
|
|
||||||
|
// FIXME: Not a missing json field, a missing header!
|
||||||
|
return Err(::ruma_api::error::RequestDeserializationError::new(
|
||||||
::ruma_api::exports::serde_json::Error::missing_field(
|
::ruma_api::exports::serde_json::Error::missing_field(
|
||||||
#header_name_string
|
#header_name_string
|
||||||
),
|
),
|
||||||
request,
|
request,
|
||||||
)
|
)
|
||||||
.into()
|
.into());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use ruma_api::ruma_api;
|
use std::convert::TryFrom;
|
||||||
use ruma_identifiers::UserId;
|
|
||||||
|
use ruma_api::{ruma_api, Endpoint as _};
|
||||||
|
use ruma_identifiers::{user_id, UserId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -36,10 +38,6 @@ ruma_api! {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
use ruma_identifiers::user_id;
|
|
||||||
|
|
||||||
let req = Request {
|
let req = Request {
|
||||||
hello: "hi".to_owned(),
|
hello: "hi".to_owned(),
|
||||||
world: "test".to_owned(),
|
world: "test".to_owned(),
|
||||||
|
@ -5,7 +5,7 @@ use std::fmt;
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{MapAccess, Visitor},
|
de::{Error as _, MapAccess, Visitor},
|
||||||
ser::SerializeStruct,
|
ser::SerializeStruct,
|
||||||
Deserialize, Deserializer, Serialize, Serializer,
|
Deserialize, Deserializer, Serialize, Serializer,
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@ use js_int::UInt;
|
|||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{MapAccess, Visitor},
|
de::{Error as _, MapAccess, Visitor},
|
||||||
ser::SerializeStruct,
|
ser::SerializeStruct,
|
||||||
Deserialize, Deserializer, Serialize, Serializer,
|
Deserialize, Deserializer, Serialize, Serializer,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user