parent
07c2d539d0
commit
0bcce9fd6f
|
@ -11,7 +11,7 @@ pub enum Body {
|
||||||
|
|
||||||
impl From<Document> for Body {
|
impl From<Document> for Body {
|
||||||
fn from(document: Document) -> Self {
|
fn from(document: Document) -> Self {
|
||||||
Body::from(document.to_string())
|
Self::from(document.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl Document {
|
||||||
.map(URIReference::into_owned)
|
.map(URIReference::into_owned)
|
||||||
.or_else(|_| ".".try_into()).expect("Northstar BUG");
|
.or_else(|_| ".".try_into()).expect("Northstar BUG");
|
||||||
let label = LinkLabel::from_lossy(label);
|
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);
|
let link = Item::Link(link);
|
||||||
|
|
||||||
self.add_item(link);
|
self.add_item(link);
|
||||||
|
@ -213,7 +213,7 @@ impl Document {
|
||||||
.map(URIReference::into_owned)
|
.map(URIReference::into_owned)
|
||||||
.or_else(|_| ".".try_into()).expect("Northstar BUG");
|
.or_else(|_| ".".try_into()).expect("Northstar BUG");
|
||||||
let link = Link {
|
let link = Link {
|
||||||
uri,
|
uri: Box::new(uri),
|
||||||
label: None,
|
label: None,
|
||||||
};
|
};
|
||||||
let link = Item::Link(link);
|
let link = Item::Link(link);
|
||||||
|
@ -391,6 +391,7 @@ impl fmt::Display for Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
enum Item {
|
enum Item {
|
||||||
Text(Text),
|
Text(Text),
|
||||||
Link(Link),
|
Link(Link),
|
||||||
|
@ -414,7 +415,7 @@ impl Text {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Link {
|
struct Link {
|
||||||
uri: URIReference<'static>,
|
uri: Box<URIReference<'static>>,
|
||||||
label: Option<LinkLabel>,
|
label: Option<LinkLabel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +425,7 @@ impl LinkLabel {
|
||||||
fn from_lossy(line: impl Cowy<str>) -> Self {
|
fn from_lossy(line: impl Cowy<str>) -> Self {
|
||||||
let line = strip_newlines(line);
|
let line = strip_newlines(line);
|
||||||
|
|
||||||
LinkLabel(line)
|
Self(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ impl Meta {
|
||||||
/// Creates a new "Meta" string.
|
/// Creates a new "Meta" string.
|
||||||
/// Fails if `meta` contains `\n`.
|
/// Fails if `meta` contains `\n`.
|
||||||
pub fn new(meta: impl Cowy<str>) -> Result<Self> {
|
pub fn new(meta: impl Cowy<str>) -> Result<Self> {
|
||||||
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);
|
ensure!(meta.as_ref().len() <= Self::MAX_LEN, "Meta must not exceed {} bytes", Self::MAX_LEN);
|
||||||
|
|
||||||
Ok(Self(meta.into()))
|
Ok(Self(meta.into()))
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl Request {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uri(&self) -> &URIReference {
|
pub const fn uri(&self) -> &URIReference {
|
||||||
&self.uri
|
&self.uri
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ impl Request {
|
||||||
self.certificate = cert;
|
self.certificate = cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn certificate(&self) -> Option<&Certificate> {
|
pub const fn certificate(&self) -> Option<&Certificate> {
|
||||||
self.certificate.as_ref()
|
self.certificate.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub struct Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
pub fn new(header: ResponseHeader) -> Self {
|
pub const fn new(header: ResponseHeader) -> Self {
|
||||||
Self {
|
Self {
|
||||||
header,
|
header,
|
||||||
body: None,
|
body: None,
|
||||||
|
@ -34,7 +34,7 @@ impl Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn success(mime: &Mime) -> Self {
|
pub fn success(mime: &Mime) -> Self {
|
||||||
let header = ResponseHeader::success(&mime);
|
let header = ResponseHeader::success(mime);
|
||||||
Self::new(header)
|
Self::new(header)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ impl Response {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn header(&self) -> &ResponseHeader {
|
pub const fn header(&self) -> &ResponseHeader {
|
||||||
&self.header
|
&self.header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,11 +88,11 @@ impl ResponseHeader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status(&self) -> &Status {
|
pub const fn status(&self) -> &Status {
|
||||||
&self.status
|
&self.status
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn meta(&self) -> &Meta {
|
pub const fn meta(&self) -> &Meta {
|
||||||
&self.meta
|
&self.meta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#[derive(Debug,Copy,Clone,PartialEq,Eq)]
|
#[derive(Debug,Copy,Clone,PartialEq,Eq)]
|
||||||
pub struct Status(u8);
|
pub struct Status(u8);
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ impl Status {
|
||||||
pub const CERTIFICATE_NOT_AUTHORIZED: Self = Self(61);
|
pub const CERTIFICATE_NOT_AUTHORIZED: Self = Self(61);
|
||||||
pub const CERTIFICATE_NOT_VALID: Self = Self(62);
|
pub const CERTIFICATE_NOT_VALID: Self = Self(62);
|
||||||
|
|
||||||
pub fn code(&self) -> u8 {
|
pub const fn code(&self) -> u8 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ impl Status {
|
||||||
self.category().is_success()
|
self.category().is_success()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn category(&self) -> StatusCategory {
|
pub const fn category(&self) -> StatusCategory {
|
||||||
let class = self.0 / 10;
|
let class = self.0 / 10;
|
||||||
|
|
||||||
match class {
|
match class {
|
||||||
|
|
Loading…
Reference in New Issue