diff options
author | Conrad Ludgate <conradludgate@gmail.com> | 2021-05-09 21:17:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-09 21:17:24 +0100 |
commit | de2e34ac500c17e80fe4dcf2ed1c08add8998fa3 (patch) | |
tree | aca08817ace6e0bd6a7dfc21615b2ed8b62f3a05 /atuin-common/src | |
parent | e43e5ce74a85d87a625295b9b089a1b5b8e26fab (diff) |
some changes :shrug: (#83)
* make everything a cow
* fmt + clippy
Diffstat (limited to 'atuin-common/src')
-rw-r--r-- | atuin-common/src/api.rs | 62 | ||||
-rw-r--r-- | atuin-common/src/lib.rs | 3 |
2 files changed, 32 insertions, 33 deletions
diff --git a/atuin-common/src/api.rs b/atuin-common/src/api.rs index 44a73c1cf..aaf8f6c5f 100644 --- a/atuin-common/src/api.rs +++ b/atuin-common/src/api.rs @@ -1,43 +1,43 @@ -use std::convert::Infallible; +use std::{borrow::Cow, convert::Infallible}; use chrono::Utc; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use warp::{reply::Response, Reply}; #[derive(Debug, Serialize, Deserialize)] -pub struct UserResponse { - pub username: String, +pub struct UserResponse<'a> { + pub username: Cow<'a, str>, } #[derive(Debug, Serialize, Deserialize)] -pub struct RegisterRequest { - pub email: String, - pub username: String, - pub password: String, +pub struct RegisterRequest<'a> { + pub email: Cow<'a, str>, + pub username: Cow<'a, str>, + pub password: Cow<'a, str>, } #[derive(Debug, Serialize, Deserialize)] -pub struct RegisterResponse { - pub session: String, +pub struct RegisterResponse<'a> { + pub session: Cow<'a, str>, } #[derive(Debug, Serialize, Deserialize)] -pub struct LoginRequest { - pub username: String, - pub password: String, +pub struct LoginRequest<'a> { + pub username: Cow<'a, str>, + pub password: Cow<'a, str>, } #[derive(Debug, Serialize, Deserialize)] -pub struct LoginResponse { - pub session: String, +pub struct LoginResponse<'a> { + pub session: Cow<'a, str>, } #[derive(Debug, Serialize, Deserialize)] -pub struct AddHistoryRequest { - pub id: String, +pub struct AddHistoryRequest<'a, D> { + pub id: Cow<'a, str>, pub timestamp: chrono::DateTime<Utc>, - pub data: String, - pub hostname: String, + pub data: D, + pub hostname: Cow<'a, str>, } #[derive(Debug, Serialize, Deserialize)] @@ -46,10 +46,10 @@ pub struct CountResponse { } #[derive(Debug, Serialize, Deserialize)] -pub struct SyncHistoryRequest { +pub struct SyncHistoryRequest<'a> { pub sync_ts: chrono::DateTime<chrono::FixedOffset>, pub history_ts: chrono::DateTime<chrono::FixedOffset>, - pub host: String, + pub host: Cow<'a, str>, } #[derive(Debug, Serialize, Deserialize)] @@ -58,38 +58,38 @@ pub struct SyncHistoryResponse { } #[derive(Debug, Serialize, Deserialize)] -pub struct ErrorResponse { - pub reason: String, +pub struct ErrorResponse<'a> { + pub reason: Cow<'a, str>, } -impl Reply for ErrorResponse { +impl Reply for ErrorResponse<'_> { fn into_response(self) -> Response { warp::reply::json(&self).into_response() } } -pub struct ErrorResponseStatus { - pub error: ErrorResponse, +pub struct ErrorResponseStatus<'a> { + pub error: ErrorResponse<'a>, pub status: warp::http::StatusCode, } -impl Reply for ErrorResponseStatus { +impl Reply for ErrorResponseStatus<'_> { fn into_response(self) -> Response { warp::reply::with_status(self.error, self.status).into_response() } } -impl ErrorResponse { - pub fn with_status(self, status: warp::http::StatusCode) -> ErrorResponseStatus { +impl<'a> ErrorResponse<'a> { + pub fn with_status(self, status: warp::http::StatusCode) -> ErrorResponseStatus<'a> { ErrorResponseStatus { error: self, status, } } - pub fn reply(reason: &str) -> ErrorResponse { + pub fn reply(reason: &'a str) -> ErrorResponse { Self { - reason: reason.to_string(), + reason: reason.into(), } } } diff --git a/atuin-common/src/lib.rs b/atuin-common/src/lib.rs index 0a01e10dd..e76a7abbf 100644 --- a/atuin-common/src/lib.rs +++ b/atuin-common/src/lib.rs @@ -1,5 +1,4 @@ -#[macro_use] -extern crate serde_derive; +#![forbid(unsafe_code)] pub mod api; pub mod utils; |