From 0bcce9fd6fbbaea403119b91aa0b7017b6612b90 Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Thu, 19 Nov 2020 17:58:33 -0500 Subject: [PATCH] Appease clippy Please my compiler is so angry ;-; --- src/types/body.rs | 2 +- src/types/document.rs | 9 +++++---- src/types/meta.rs | 2 +- src/types/request.rs | 4 ++-- src/types/response.rs | 6 +++--- src/types/response_header.rs | 4 ++-- src/types/status.rs | 5 ++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/types/body.rs b/src/types/body.rs index d1356cc..d2da102 100644 --- a/src/types/body.rs +++ b/src/types/body.rs @@ -11,7 +11,7 @@ pub enum Body { impl From for Body { fn from(document: Document) -> Self { - Body::from(document.to_string()) + Self::from(document.to_string()) } } diff --git a/src/types/document.rs b/src/types/document.rs index e322357..d71c851 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -183,7 +183,7 @@ impl Document { .map(URIReference::into_owned) .or_else(|_| ".".try_into()).expect("Northstar BUG"); let label = LinkLabel::from_lossy(label); - let link = Link { uri, label: Some(label) }; + let link = Link { uri: Box::new(uri), label: Some(label) }; let link = Item::Link(link); self.add_item(link); @@ -213,7 +213,7 @@ impl Document { .map(URIReference::into_owned) .or_else(|_| ".".try_into()).expect("Northstar BUG"); let link = Link { - uri, + uri: Box::new(uri), label: None, }; let link = Item::Link(link); @@ -391,6 +391,7 @@ impl fmt::Display for Document { } } +#[allow(clippy::enum_variant_names)] enum Item { Text(Text), Link(Link), @@ -414,7 +415,7 @@ impl Text { } struct Link { - uri: URIReference<'static>, + uri: Box>, label: Option, } @@ -424,7 +425,7 @@ impl LinkLabel { fn from_lossy(line: impl Cowy) -> Self { let line = strip_newlines(line); - LinkLabel(line) + Self(line) } } diff --git a/src/types/meta.rs b/src/types/meta.rs index ccc17ba..bfb36e5 100644 --- a/src/types/meta.rs +++ b/src/types/meta.rs @@ -12,7 +12,7 @@ impl Meta { /// Creates a new "Meta" string. /// Fails if `meta` contains `\n`. pub fn new(meta: impl Cowy) -> Result { - ensure!(!meta.as_ref().contains("\n"), "Meta must not contain newlines"); + ensure!(!meta.as_ref().contains('\n'), "Meta must not contain newlines"); ensure!(meta.as_ref().len() <= Self::MAX_LEN, "Meta must not exceed {} bytes", Self::MAX_LEN); Ok(Self(meta.into())) diff --git a/src/types/request.rs b/src/types/request.rs index a99ea2f..76eace2 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -39,7 +39,7 @@ impl Request { }) } - pub fn uri(&self) -> &URIReference { + pub const fn uri(&self) -> &URIReference { &self.uri } @@ -60,7 +60,7 @@ impl Request { self.certificate = cert; } - pub fn certificate(&self) -> Option<&Certificate> { + pub const fn certificate(&self) -> Option<&Certificate> { self.certificate.as_ref() } } diff --git a/src/types/response.rs b/src/types/response.rs index 3e4a84a..991d511 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -12,7 +12,7 @@ pub struct Response { } impl Response { - pub fn new(header: ResponseHeader) -> Self { + pub const fn new(header: ResponseHeader) -> Self { Self { header, body: None, @@ -34,7 +34,7 @@ impl Response { } pub fn success(mime: &Mime) -> Self { - let header = ResponseHeader::success(&mime); + let header = ResponseHeader::success(mime); Self::new(header) } @@ -86,7 +86,7 @@ impl Response { self } - pub fn header(&self) -> &ResponseHeader { + pub const fn header(&self) -> &ResponseHeader { &self.header } diff --git a/src/types/response_header.rs b/src/types/response_header.rs index 56f2af3..b2b5e20 100644 --- a/src/types/response_header.rs +++ b/src/types/response_header.rs @@ -88,11 +88,11 @@ impl ResponseHeader { } } - pub fn status(&self) -> &Status { + pub const fn status(&self) -> &Status { &self.status } - pub fn meta(&self) -> &Meta { + pub const fn meta(&self) -> &Meta { &self.meta } } diff --git a/src/types/status.rs b/src/types/status.rs index a06e9f4..18c58a1 100644 --- a/src/types/status.rs +++ b/src/types/status.rs @@ -1,4 +1,3 @@ - #[derive(Debug,Copy,Clone,PartialEq,Eq)] pub struct Status(u8); @@ -22,7 +21,7 @@ impl Status { pub const CERTIFICATE_NOT_AUTHORIZED: Self = Self(61); pub const CERTIFICATE_NOT_VALID: Self = Self(62); - pub fn code(&self) -> u8 { + pub const fn code(&self) -> u8 { self.0 } @@ -30,7 +29,7 @@ impl Status { self.category().is_success() } - pub fn category(&self) -> StatusCategory { + pub const fn category(&self) -> StatusCategory { let class = self.0 / 10; match class {