<commit_before>use std::fs::File;
use std::fmt;

use http::mime::{Mime, TopLevel, SubLevel};
use http::hyper::{header, FreshHyperResponse, StatusCode};
use outcome::{self, IntoOutcome};
use outcome::Outcome::*;
use response::Stream;


/// Type alias for the `Outcome` of a `Responder`.
pub type Outcome<'a> = outcome::Outcome<(), (), (StatusCode, FreshHyperResponse<'a>)>;

impl<'a, T, E> IntoOutcome<(), (), (StatusCode, FreshHyperResponse<'a>)> for Result<T, E> {
    fn into_outcome(self) -> Outcome<'a> {
        match self {
            Ok(_) => Success(()),
            Err(_) => Failure(())
        }
    }
}

/// Trait implemented by types that send a response to clients.
///
/// Types that implement this trait can be used as the return type of a handler,
/// as illustrated below:
///
/// ```rust,ignore
/// #[get("/")]
/// fn index() -> T { ... }
/// ```
///
/// In this example, `T` can be any type that implements `Responder`.
///
/// # Outcomes
///
/// The returned [Outcome](/rocket/outcome/index.html) of a `respond` call
/// determines how the response will be processed, if at all.
///
/// * **Success**
///
///   An `Outcome` of `Success` indicates that the responder was successful in
///   sending the response to the client. No further processing will occur as a
///   result.
///
/// * **Failure**
///
///   An `Outcome` of `Failure` indicates that the responder failed after
///   beginning a response. The response is incomplete, and there is no way to
///   salvage the response. No further processing will occur.
///
/// * **Forward**(StatusCode, FreshHyperResponse<'a>)
///
///   If the `Outcome` is `Forward`, the response will be forwarded to the
///   designated error [Catcher](/rocket/struct.Catcher.html) for the given
///   `StatusCode`. This requires that a response wasn't started and thus is
///   still fresh.
///
/// # Provided Implementations
///
/// Rocket implements `Responder` for several standard library types. Their
/// behavior is documented here. Note that the `Result` implementation is
/// overloaded, allowing for two `Responder`s to be used at once, depending on
/// the variant.
///
///   * **impl<'a> Responder for &'a str**
///
///     Sets the `Content-Type`t to `text/plain` if it is not already set. Sends
///     the string as the body of the response.
///
///   * **impl Responder for String**
///
///     Sets the `Content-Type`t to `text/html` if it is not already set. Sends
///     the string as the body of the response.
///
///   * **impl Responder for File**
///
///     Streams the `File` to the client. This is essentially an alias to
///     Stream<File>.
///
///   * **impl Responder for ()**
///
///     Responds with an empty body.
///
///   * **impl<T: Responder> Responder for Option<T>**
///
///     If the `Option` is `Some`, the wrapped responder is used to respond to
///     respond to the client. Otherwise, the response is forwarded to the 404
///     error catcher and a warning is printed to the console.
///
///   * **impl<T: Responder, E: Debug> Responder for Result<T, E>**
///
///     If the `Result` is `Ok`, the wrapped responder is used to respond to the
///     client. Otherwise, the response is forwarded to the 500 error catcher
///     and the error is printed to the console using the `Debug`
///     implementation.
///
///   * **impl<T: Responder, E: Responder + Debug> Responder for Result<T, E>**
///
///     If the `Result` is `Ok`, the wrapped `Ok` responder is used to respond
///     to the client. If the `Result` is `Err`, the wrapped error responder is
///     used to respond to the client.
///
/// # Implementation Tips
///
/// This section describes a few best practices to take into account when
/// implementing `Responder`.
///
/// ## Debug
///
/// A type implementing `Responder` should implement the `Debug` trait when
/// possible. This is because the `Responder` implementation for `Result`
/// requires its `Err` type to implement `Debug`. Therefore, a type implementing
/// `Debug` can more easily be composed.
///
/// ## Check Before Changing
///
/// Unless a given type is explicitly designed to change some information in the
/// response, it should first _check_ that some information hasn't been set
/// before _changing_ that information. For example, before setting the
/// `Content-Type` header of a response, first check that the header hasn't been
/// set.
///
/// # Example
///
/// Say that you have a custom type, `Person`:
///<commit_msg>HTML escape < in Responder docs.<commit_after>use std::fs::File;
use std::fmt;

use http::mime::{Mime, TopLevel, SubLevel};
use http::hyper::{header, FreshHyperResponse, StatusCode};
use outcome::{self, IntoOutcome};
use outcome::Outcome::*;
use response::Stream;


/// Type alias for the `Outcome` of a `Responder`.
pub type Outcome<'a> = outcome::Outcome<(), (), (StatusCode, FreshHyperResponse<'a>)>;

impl<'a, T, E> IntoOutcome<(), (), (StatusCode, FreshHyperResponse<'a>)> for Result<T, E> {
    fn into_outcome(self) -> Outcome<'a> {
        match self {
            Ok(_) => Success(()),
            Err(_) => Failure(())
        }
    }
}

/// Trait implemented by types that send a response to clients.
///
/// Types that implement this trait can be used as the return type of a handler,
/// as illustrated below:
///
/// ```rust,ignore
/// #[get("/")]
/// fn index() -> T { ... }
/// ```
///
/// In this example, `T` can be any type that implements `Responder`.
///
/// # Outcomes
///
/// The returned [Outcome](/rocket/outcome/index.html) of a `respond` call
/// determines how the response will be processed, if at all.
///
/// * **Success**
///
///   An `Outcome` of `Success` indicates that the responder was successful in
///   sending the response to the client. No further processing will occur as a
///   result.
///
/// * **Failure**
///
///   An `Outcome` of `Failure` indicates that the responder failed after
///   beginning a response. The response is incomplete, and there is no way to
///   salvage the response. No further processing will occur.
///
/// * **Forward**(StatusCode, FreshHyperResponse<'a>)
///
///   If the `Outcome` is `Forward`, the response will be forwarded to the
///   designated error [Catcher](/rocket/struct.Catcher.html) for the given
///   `StatusCode`. This requires that a response wasn't started and thus is
///   still fresh.
///
/// # Provided Implementations
///
/// Rocket implements `Responder` for several standard library types. Their
/// behavior is documented here. Note that the `Result` implementation is
/// overloaded, allowing for two `Responder`s to be used at once, depending on
/// the variant.
///
///   * **impl<'a> Responder for &'a str**
///
///     Sets the `Content-Type`t to `text/plain` if it is not already set. Sends
///     the string as the body of the response.
///
///   * **impl Responder for String**
///
///     Sets the `Content-Type`t to `text/html` if it is not already set. Sends
///     the string as the body of the response.
///
///   * **impl Responder for File**
///
///     Streams the `File` to the client. This is essentially an alias to
///     Stream<File>.
///
///   * **impl Responder for ()**
///
///     Responds with an empty body.
///
///   * **impl&lt;T: Responder> Responder for Option&lt;T>**
///
///     If the `Option` is `Some`, the wrapped responder is used to respond to
///     respond to the client. Otherwise, the response is forwarded to the 404
///     error catcher and a warning is printed to the console.
///
///   * **impl&lt;T: Responder, E: Debug> Responder for Result&lt;T, E>**
///
///     If the `Result` is `Ok`, the wrapped responder is used to respond to the
///     client. Otherwise, the response is forwarded to the 500 error catcher
///     and the error is printed to the console using the `Debug`
///     implementation.
///
///   * **impl&lt;T: Responder, E: Responder + Debug> Responder for Result&lt;T, E>**
///
///     If the `Result` is `Ok`, the wrapped `Ok` responder is used to respond
///     to the client. If the `Result` is `Err`, the wrapped error responder is
///     used to respond to the client.
///
/// # Implementation Tips
///
/// This section describes a few best practices to take into account when
/// implementing `Responder`.
///
/// ## Debug
///
/// A type implementing `Responder` should implement the `Debug` trait when
/// possible. This is because the `Responder` implementation for `Result`
/// requires its `Err` type to implement `Debug`. Therefore, a type implementing
/// `Debug` can more easily be composed.
///
/// ## Check Before Changing
///
/// Unless a given type is explicitly designed to change some information in the
/// response, it should first _check_ that some information hasn't been set
/// before _changing_ that information. For example, before setting the
/// `Content-Type` header of a response, first check that the header hasn't been
/// set.
///
/// # Example
///
/// Say that you have a custom type, `Person`:
///
{'fraction_non_alphanumeric': 0.15915414579855314, 'fraction_numerical': 0.001335559265442404, 'mean_word_length': 2.687320475995076, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7365070', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2542, 'n_words': 1104}