Struct Template

Source
pub struct Template<'a> { /* private fields */ }
Expand description

Modifiable reason for creating a response to the client.

Not all responses indicate failure. A redirect will also occur in the a regular of providing an access token to the third party client. When an error is present (see several methods) it is mostly possible to customize it. This hook provides advanced endpoints with the opportunity to set additional parameters and informational messages before they are encoded.

See the provided methods for more information and examples.

Implementations§

Source§

impl<'a> Template<'a>

Source

pub fn new_ok() -> Self

Create an OK template

Source

pub fn new_bad(access_token_error: Option<&'a mut AccessTokenError>) -> Self

Create a bad request template

Source

pub fn new_unauthorized( error: Option<ResourceError>, access_token_error: Option<&'a mut AccessTokenError>, ) -> Self

Create an unauthorized template

Source

pub fn new_redirect( authorization_error: Option<&'a mut AuthorizationError>, ) -> Self

Create a redirect template

Source

pub fn status(&self) -> ResponseStatus

The corresponding status code.

Source

pub fn authorization_error(&mut self) -> Option<&mut AuthorizationError>

Supplementary information about an error in the authorization code flow.

The referenced object can be inspected and manipulated to provided additional information that is specific to this server or endpoint. Such information could be an error page with explanatory information or a customized message.

fn explain(mut template: Template) {
    if let Some(error) = template.authorization_error() {
        eprintln!("[authorization] An error occurred: {:?}", error.kind());
        error.explain("This server is still in its infancy. Sorry.");
        error.explain_uri("/authorization_error.html".parse().unwrap());
    }
}
Source

pub fn access_token_error(&mut self) -> Option<&mut AccessTokenError>

Supplementary information about an error in the access token flow.

The referenced object can be inspected and manipulated to provided additional information that is specific to this server or endpoint. Such information could be an error page with explanatory information or a customized message.

fn explain(mut template: Template) {
    if let Some(error) = template.access_token_error() {
        eprintln!("[access_code] An error occurred: {:?}", error.kind());
        error.explain("This server is still in its infancy. Sorry.");
        error.explain_uri("/access_token_error.html".parse().unwrap());
    }
}

Trait Implementations§

Source§

impl<'a> Debug for Template<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Template<'a>

§

impl<'a> RefUnwindSafe for Template<'a>

§

impl<'a> Send for Template<'a>

§

impl<'a> Sync for Template<'a>

§

impl<'a> Unpin for Template<'a>

§

impl<'a> !UnwindSafe for Template<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,