From 6bd101504d5a54d9435fd01ae0fb4f57fd6f1398 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Tue, 6 Aug 2024 12:26:59 +0400 Subject: [PATCH] feat: add ensure_ok for simple 20/non-20 matching --- src/response.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index 0da2940..32eb0db 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,4 +1,4 @@ -use crate::{status::Status, LibError}; +use crate::{status::Status, LibError, ReplyType}; use bytes::Bytes; use tokio::io::AsyncReadExt; @@ -21,6 +21,14 @@ impl Response { } } + pub fn ensure_ok(self: Self) -> Result { + if self.status.reply_type() == ReplyType::Success { + Ok(self) + } else { + Err(self) + } + } + pub fn status(self: &Self) -> Status { self.status }