twilight_http::request

Trait TryIntoRequest

source
pub trait TryIntoRequest: Sealed {
    // Required method
    fn try_into_request(self) -> Result<Request, Error>;
}
Expand description

Convert a typed request builder into a raw Request.

Converting a typed request builder into a raw request may be preferable in order to verify whether a request is valid prior to passing it to Client::request.

Creating raw requests is useful for unit tests and debugging.

§Examples

Convert a CreateMessage builder into a Request, inspect its body and route, and then send the request:

use std::{env, str};
use twilight_http::{client::Client, request::TryIntoRequest};
use twilight_model::{channel::Message, id::Id};

let client = Client::new(env::var("DISCORD_TOKEN")?);
let channel_id = Id::new(1);
let builder = client
    .create_message(channel_id)
    .content("This is a test message!")
    .tts(false);

let request = builder.try_into_request()?;

println!("{:?} {}", request.method(), request.path());

if let Some(body) = request.body() {
    println!("{}", str::from_utf8(body)?);
}

// Because a raw request is being performed, the output type must be
// explicit.
let response = client.request::<Message>(request).await?;

Required Methods§

source

fn try_into_request(self) -> Result<Request, Error>

Try to convert a request builder into a raw Request.

§Errors

Not all typed request builder conversions return an error and may instead always succeed. Refer to the documentation for each implementation for clarification.

Requests may return an error type of ErrorType::CreatingHeader if creating an audit log header value fails.

Requests may return an error type of ErrorType::Json if serializing a request body fails.

Implementors§

source§

impl TryIntoRequest for CreateGlobalChatInputCommand<'_>

source§

impl TryIntoRequest for CreateGlobalMessageCommand<'_>

source§

impl TryIntoRequest for CreateGlobalUserCommand<'_>

source§

impl TryIntoRequest for CreateGuildChatInputCommand<'_>

source§

impl TryIntoRequest for CreateGuildMessageCommand<'_>

source§

impl TryIntoRequest for CreateGuildUserCommand<'_>

source§

impl TryIntoRequest for DeleteGlobalCommand<'_>

source§

impl TryIntoRequest for DeleteGuildCommand<'_>

source§

impl TryIntoRequest for GetCommandPermissions<'_>

source§

impl TryIntoRequest for GetGlobalCommand<'_>

source§

impl TryIntoRequest for GetGlobalCommands<'_>

source§

impl TryIntoRequest for GetGuildCommand<'_>

source§

impl TryIntoRequest for GetGuildCommandPermissions<'_>

source§

impl TryIntoRequest for GetGuildCommands<'_>

source§

impl TryIntoRequest for SetGlobalCommands<'_>

source§

impl TryIntoRequest for SetGuildCommands<'_>

source§

impl TryIntoRequest for UpdateCommandPermissions<'_>

source§

impl TryIntoRequest for UpdateGlobalCommand<'_>

source§

impl TryIntoRequest for UpdateGuildCommand<'_>

source§

impl TryIntoRequest for AddApplicationEmoji<'_>

source§

impl TryIntoRequest for DeleteApplicationEmoji<'_>

source§

impl TryIntoRequest for ListApplicationEmojis<'_>

source§

impl TryIntoRequest for UpdateApplicationEmoji<'_>

source§

impl TryIntoRequest for CreateFollowup<'_>

source§

impl TryIntoRequest for CreateResponse<'_>

source§

impl TryIntoRequest for DeleteFollowup<'_>

source§

impl TryIntoRequest for DeleteResponse<'_>

source§

impl TryIntoRequest for GetFollowup<'_>

source§

impl TryIntoRequest for GetResponse<'_>

source§

impl TryIntoRequest for UpdateFollowup<'_>

source§

impl TryIntoRequest for UpdateResponse<'_>

source§

impl TryIntoRequest for CreateTestEntitlement<'_>

source§

impl TryIntoRequest for DeleteTestEntitlement<'_>

source§

impl TryIntoRequest for GetEntitlements<'_>

source§

impl TryIntoRequest for GetSKUs<'_>

source§

impl TryIntoRequest for CreateInvite<'_>

source§

impl TryIntoRequest for DeleteInvite<'_>

source§

impl TryIntoRequest for GetChannelInvites<'_>

source§

impl TryIntoRequest for GetInvite<'_>

source§

impl TryIntoRequest for CreateMessage<'_>

source§

impl TryIntoRequest for CrosspostMessage<'_>

source§

impl TryIntoRequest for DeleteMessage<'_>

source§

impl TryIntoRequest for DeleteMessages<'_>

source§

impl TryIntoRequest for GetChannelMessages<'_>

source§

impl TryIntoRequest for GetChannelMessagesConfigured<'_>

source§

impl TryIntoRequest for GetMessage<'_>

source§

impl TryIntoRequest for UpdateMessage<'_>

source§

impl TryIntoRequest for CreateReaction<'_>

source§

impl TryIntoRequest for DeleteAllReaction<'_>

source§

impl TryIntoRequest for DeleteAllReactions<'_>

source§

impl TryIntoRequest for DeleteReaction<'_>

source§

impl TryIntoRequest for GetReactions<'_>

source§

impl TryIntoRequest for CreateStageInstance<'_>

source§

impl TryIntoRequest for DeleteStageInstance<'_>

source§

impl TryIntoRequest for GetStageInstance<'_>

source§

impl TryIntoRequest for UpdateStageInstance<'_>

source§

impl TryIntoRequest for CreatePin<'_>

source§

impl TryIntoRequest for CreateTypingTrigger<'_>

source§

impl TryIntoRequest for DeleteChannel<'_>

source§

impl TryIntoRequest for DeleteChannelPermissionConfigured<'_>

source§

impl TryIntoRequest for DeletePin<'_>

source§

impl TryIntoRequest for FollowNewsChannel<'_>

source§

impl TryIntoRequest for GetChannel<'_>

source§

impl TryIntoRequest for GetPins<'_>

source§

impl TryIntoRequest for UpdateChannel<'_>

source§

impl TryIntoRequest for UpdateChannelPermission<'_>

source§

impl TryIntoRequest for CreateForumThreadMessage<'_>

source§

impl TryIntoRequest for AddThreadMember<'_>

source§

impl TryIntoRequest for CreateThread<'_>

source§

impl TryIntoRequest for CreateThreadFromMessage<'_>

source§

impl TryIntoRequest for GetJoinedPrivateArchivedThreads<'_>

source§

impl TryIntoRequest for GetPrivateArchivedThreads<'_>

source§

impl TryIntoRequest for GetPublicArchivedThreads<'_>

source§

impl TryIntoRequest for GetThreadMember<'_>

source§

impl TryIntoRequest for GetThreadMembers<'_>

source§

impl TryIntoRequest for JoinThread<'_>

source§

impl TryIntoRequest for LeaveThread<'_>

source§

impl TryIntoRequest for RemoveThreadMember<'_>

source§

impl TryIntoRequest for UpdateThread<'_>

source§

impl TryIntoRequest for ExecuteWebhook<'_>

source§

impl TryIntoRequest for CreateWebhook<'_>

source§

impl TryIntoRequest for DeleteWebhook<'_>

source§

impl TryIntoRequest for DeleteWebhookMessage<'_>

source§

impl TryIntoRequest for ExecuteWebhookAndWait<'_>

source§

impl TryIntoRequest for GetChannelWebhooks<'_>

source§

impl TryIntoRequest for GetWebhook<'_>

source§

impl TryIntoRequest for GetWebhookMessage<'_>

source§

impl TryIntoRequest for UpdateWebhook<'_>

source§

impl TryIntoRequest for UpdateWebhookWithToken<'_>

source§

impl TryIntoRequest for UpdateWebhookMessage<'_>

source§

impl TryIntoRequest for CreateAutoModerationRule<'_>

source§

impl TryIntoRequest for DeleteAutoModerationRule<'_>

source§

impl TryIntoRequest for GetAutoModerationRule<'_>

source§

impl TryIntoRequest for GetGuildAutoModerationRules<'_>

source§

impl TryIntoRequest for UpdateAutoModerationRule<'_>

source§

impl TryIntoRequest for CreateBan<'_>

source§

impl TryIntoRequest for DeleteBan<'_>

source§

impl TryIntoRequest for GetBan<'_>

source§

impl TryIntoRequest for GetBans<'_>

source§

impl TryIntoRequest for CreateGuild<'_>

source§

impl TryIntoRequest for CreateEmoji<'_>

source§

impl TryIntoRequest for DeleteEmoji<'_>

source§

impl TryIntoRequest for GetEmoji<'_>

source§

impl TryIntoRequest for GetEmojis<'_>

source§

impl TryIntoRequest for UpdateEmoji<'_>

source§

impl TryIntoRequest for DeleteGuildIntegration<'_>

source§

impl TryIntoRequest for GetGuildIntegrations<'_>

source§

impl TryIntoRequest for AddGuildMember<'_>

source§

impl TryIntoRequest for AddRoleToMember<'_>

source§

impl TryIntoRequest for GetGuildMembers<'_>

source§

impl TryIntoRequest for GetMember<'_>

source§

impl TryIntoRequest for RemoveMember<'_>

source§

impl TryIntoRequest for RemoveRoleFromMember<'_>

source§

impl TryIntoRequest for SearchGuildMembers<'_>

source§

impl TryIntoRequest for UpdateGuildMember<'_>

source§

impl TryIntoRequest for CreateRole<'_>

source§

impl TryIntoRequest for DeleteRole<'_>

source§

impl TryIntoRequest for GetGuildRoles<'_>

source§

impl TryIntoRequest for UpdateRole<'_>

source§

impl TryIntoRequest for UpdateRolePositions<'_>

source§

impl TryIntoRequest for CreateGuildSticker<'_>

source§

impl TryIntoRequest for DeleteGuildSticker<'_>

source§

impl TryIntoRequest for GetGuildSticker<'_>

source§

impl TryIntoRequest for GetGuildStickers<'_>

source§

impl TryIntoRequest for UpdateGuildSticker<'_>

source§

impl TryIntoRequest for CreateGuildChannel<'_>

source§

impl TryIntoRequest for CreateGuildPrune<'_>

source§

impl TryIntoRequest for DeleteGuild<'_>

source§

impl TryIntoRequest for GetActiveThreads<'_>

source§

impl TryIntoRequest for GetAuditLog<'_>

source§

impl TryIntoRequest for GetGuild<'_>

source§

impl TryIntoRequest for GetGuildChannels<'_>

source§

impl TryIntoRequest for GetGuildInvites<'_>

source§

impl TryIntoRequest for GetGuildOnboarding<'_>

source§

impl TryIntoRequest for GetGuildPreview<'_>

source§

impl TryIntoRequest for GetGuildPruneCount<'_>

source§

impl TryIntoRequest for GetGuildVanityUrl<'_>

source§

impl TryIntoRequest for GetGuildVoiceRegions<'_>

source§

impl TryIntoRequest for GetGuildWebhooks<'_>

source§

impl TryIntoRequest for GetGuildWelcomeScreen<'_>

source§

impl TryIntoRequest for GetGuildWidget<'_>

source§

impl TryIntoRequest for GetGuildWidgetSettings<'_>

source§

impl TryIntoRequest for UpdateCurrentMember<'_>

source§

impl TryIntoRequest for UpdateGuild<'_>

source§

impl TryIntoRequest for UpdateGuildMfa<'_>

source§

impl TryIntoRequest for UpdateGuildWelcomeScreen<'_>

source§

impl TryIntoRequest for UpdateGuildWidgetSettings<'_>

source§

impl TryIntoRequest for UpdateGuildChannelPositions<'_>

source§

impl TryIntoRequest for UpdateGuildOnboarding<'_>

source§

impl TryIntoRequest for UpdateCurrentUserVoiceState<'_>

source§

impl TryIntoRequest for UpdateUserVoiceState<'_>

source§

impl TryIntoRequest for EndPoll<'_>

source§

impl TryIntoRequest for GetAnswerVoters<'_>

source§

impl TryIntoRequest for CreateGuildExternalScheduledEvent<'_>

source§

impl TryIntoRequest for CreateGuildStageInstanceScheduledEvent<'_>

source§

impl TryIntoRequest for CreateGuildVoiceScheduledEvent<'_>

source§

impl TryIntoRequest for DeleteGuildScheduledEvent<'_>

source§

impl TryIntoRequest for GetGuildScheduledEvent<'_>

source§

impl TryIntoRequest for GetGuildScheduledEventUsers<'_>

source§

impl TryIntoRequest for GetGuildScheduledEvents<'_>

source§

impl TryIntoRequest for UpdateGuildScheduledEvent<'_>

source§

impl TryIntoRequest for GetNitroStickerPacks<'_>

source§

impl TryIntoRequest for GetSticker<'_>

source§

impl TryIntoRequest for GetCurrentAuthorizationInformation<'_>

source§

impl TryIntoRequest for GetGateway<'_>

source§

impl TryIntoRequest for GetGatewayAuthed<'_>

source§

impl TryIntoRequest for GetUserApplicationInfo<'_>

source§

impl TryIntoRequest for GetVoiceRegions<'_>

source§

impl TryIntoRequest for UpdateCurrentUserApplication<'_>

source§

impl TryIntoRequest for CreateGuildFromTemplate<'_>

source§

impl TryIntoRequest for CreateTemplate<'_>

source§

impl TryIntoRequest for DeleteTemplate<'_>

source§

impl TryIntoRequest for GetTemplate<'_>

source§

impl TryIntoRequest for GetTemplates<'_>

source§

impl TryIntoRequest for SyncTemplate<'_>

source§

impl TryIntoRequest for UpdateTemplate<'_>

source§

impl TryIntoRequest for CreatePrivateChannel<'_>

source§

impl TryIntoRequest for GetCurrentUser<'_>

source§

impl TryIntoRequest for GetCurrentUserConnections<'_>

source§

impl TryIntoRequest for GetCurrentUserGuildMember<'_>

source§

impl TryIntoRequest for GetCurrentUserGuilds<'_>

source§

impl TryIntoRequest for GetUser<'_>

source§

impl TryIntoRequest for LeaveGuild<'_>

source§

impl TryIntoRequest for UpdateCurrentUser<'_>