Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions cot-core/src/error/error_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,6 @@ impl Error {
}
}

/// Create a new error with a custom error message or error type.
///
/// # Examples
///
/// ```
/// use cot::Error;
///
/// let error = Error::custom("An error occurred");
/// let error = Error::custom(std::io::Error::new(
/// std::io::ErrorKind::Other,
/// "An error occurred",
/// ));
/// ```
#[deprecated(
note = "Use `cot::Error::internal` or `cot::Error::with_status` instead",
since = "0.4.0"
)]
#[must_use]
pub fn custom<E>(error: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
{
Self::internal(error)
}

/// Create a new error with a custom error message or error type.
///
/// The error will be associated with a 500 Internal Server Error
Expand Down Expand Up @@ -124,32 +99,6 @@ impl Error {
Self::wrap(WithStatusCode(error))
}

/// Create a new admin panel error with a custom error message or error
/// type.
///
/// # Examples
///
/// ```
/// use cot::Error;
///
/// let error = Error::admin("An error occurred");
/// let error = Error::admin(std::io::Error::new(
/// std::io::ErrorKind::Other,
/// "An error occurred",
/// ));
/// ```
#[deprecated(
note = "Use `cot::Error::wrap`, `cot::Error::internal`, or \
`cot::Error::with_status` directly instead",
since = "0.4.0"
)]
pub fn admin<E>(error: E) -> Self
where
E: Into<Box<dyn StdError + Send + Sync + 'static>>,
{
Self::internal(error)
}

/// Returns the HTTP status code associated with this error.
///
/// This method returns the appropriate HTTP status code that should be
Expand Down
48 changes: 2 additions & 46 deletions cot-core/src/response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Body, StatusCode};
use crate::Body;
mod into_response;

/// Derive macro for the [`IntoResponse`] trait.
Expand Down Expand Up @@ -90,30 +90,6 @@ pub trait ResponseExt: Sized + private::Sealed {
/// ```
#[must_use]
fn builder() -> http::response::Builder;

/// Create a new redirect response.
///
/// This creates a new [`Response`] object with a status code of
/// [`StatusCode::SEE_OTHER`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/303)
/// and a `Location` header set to the provided location.
///
/// # Examples
///
/// ```
/// use cot::StatusCode;
/// use cot::response::{Response, ResponseExt};
///
/// let response = Response::new_redirect("http://example.com");
/// ```
///
/// # See also
///
/// * [`cot::reverse_redirect!`](../../cot/macro.reverse_redirect!.html) – a
/// more ergonomic way to create redirects to internal views (available in
/// the `cot` crate)
#[must_use]
#[deprecated(since = "0.5.0", note = "Use Redirect::new() instead")]
fn new_redirect<T: Into<String>>(location: T) -> Self;
}

impl private::Sealed for Response {}
Expand All @@ -122,14 +98,6 @@ impl ResponseExt for Response {
fn builder() -> http::response::Builder {
http::Response::builder()
}

fn new_redirect<T: Into<String>>(location: T) -> Self {
http::Response::builder()
.status(StatusCode::SEE_OTHER)
.header(http::header::LOCATION, location.into())
.body(Body::empty())
.expect(RESPONSE_BUILD_FAILURE)
}
}

/// A redirect response.
Expand Down Expand Up @@ -182,9 +150,9 @@ impl Redirect {
#[cfg(test)]
mod tests {
use super::*;
use crate::StatusCode;
use crate::body::BodyInner;
use crate::headers::JSON_CONTENT_TYPE;
use crate::response::{Response, ResponseExt};

#[test]
#[cfg(feature = "json")]
Expand Down Expand Up @@ -213,18 +181,6 @@ mod tests {
}
}

#[test]
#[expect(deprecated)]
fn response_new_redirect() {
let location = "http://example.com";
let response = Response::new_redirect(location);
assert_eq!(response.status(), StatusCode::SEE_OTHER);
assert_eq!(
response.headers().get(http::header::LOCATION).unwrap(),
location
);
}

#[test]
fn response_new_redirect_struct() {
let location = "http://example.com";
Expand Down
32 changes: 0 additions & 32 deletions cot/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,6 @@ pub trait RequestExt: private::Sealed {
#[must_use]
fn path_params_mut(&mut self) -> &mut PathParams;

/// Get the database.
///
/// # Examples
///
/// ```
/// use cot::request::{Request, RequestExt};
/// use cot::response::Response;
///
/// async fn my_handler(mut request: Request) -> cot::Result<Response> {
/// let db = request.db();
/// // ... do something with the database
/// # unimplemented!()
/// }
/// ```
#[cfg(feature = "db")]
#[must_use]
#[deprecated(
since = "0.5.0",
note = "use request extractors (`FromRequestHead`) instead"
)]
fn db(&self) -> &crate::db::Database;

/// Get the content type of the request.
///
/// # Examples
Expand Down Expand Up @@ -315,11 +293,6 @@ impl RequestExt for Request {
self.extensions_mut().get_or_insert_default::<PathParams>()
}

#[cfg(feature = "db")]
fn db(&self) -> &crate::db::Database {
self.context().database()
}

fn content_type(&self) -> Option<&http::HeaderValue> {
self.headers().get(http::header::CONTENT_TYPE)
}
Expand Down Expand Up @@ -375,11 +348,6 @@ impl RequestExt for RequestHead {
self.extensions.get_or_insert_default::<PathParams>()
}

#[cfg(feature = "db")]
fn db(&self) -> &crate::db::Database {
self.context().database()
}

fn content_type(&self) -> Option<&http::HeaderValue> {
self.headers.get(http::header::CONTENT_TYPE)
}
Expand Down
Loading