make no_std compatible

This commit is contained in:
Robin Appelman 2024-12-11 21:49:01 +01:00
commit d06978a34a
3 changed files with 18 additions and 11 deletions

2
Cargo.lock generated
View file

@ -4,7 +4,7 @@ version = 3
[[package]] [[package]]
name = "rfc7239" name = "rfc7239"
version = "0.1.2" version = "0.1.3"
dependencies = [ dependencies = [
"uncased", "uncased",
] ]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "rfc7239" name = "rfc7239"
version = "0.1.2" version = "0.1.3"
authors = ["Robin Appelman <robin@icewind.nl>"] authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018" edition = "2018"
description = "Parser for rfc7239 formatted Forwarded headers" description = "Parser for rfc7239 formatted Forwarded headers"

View file

@ -1,10 +1,11 @@
#![no_std]
//! Parser for [rfc7239] formatted `Forwarded` headers. //! Parser for [rfc7239] formatted `Forwarded` headers.
//! //!
//! ## Usage //! ## Usage
//! //!
//! ``` //! ```
//! use rfc7239::parse; //! use rfc7239::parse;
//! # use std::error::Error; //! # use core::error::Error;
//! //!
//! # fn main() -> Result<(), Box<dyn Error>> { //! # fn main() -> Result<(), Box<dyn Error>> {
//! // get the header value from your favorite http server library //! // get the header value from your favorite http server library
@ -21,10 +22,16 @@
//! ``` //! ```
//! //!
//! [rfc7239]: https://tools.ietf.org/html/rfc7239 //! [rfc7239]: https://tools.ietf.org/html/rfc7239
use std::error::Error;
use std::fmt::{Debug, Display, Formatter}; #[cfg(test)]
use std::net::IpAddr; extern crate std;
use std::str::FromStr; #[cfg(test)]
use std::{format, vec, vec::Vec};
use core::error::Error;
use core::fmt::{Debug, Display, Formatter};
use core::net::IpAddr;
use core::str::FromStr;
use uncased::UncasedStr; use uncased::UncasedStr;
#[derive(Debug)] #[derive(Debug)]
@ -36,7 +43,7 @@ pub enum RfcError {
} }
impl Display for RfcError { impl Display for RfcError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
let str = match self { let str = match self {
RfcError::InvalidIdentifier => "Invalid node identifier", RfcError::InvalidIdentifier => "Invalid node identifier",
RfcError::InvalidPort => "Invalid node port", RfcError::InvalidPort => "Invalid node port",
@ -115,7 +122,7 @@ impl<'a> Forwarded<'a> {
} }
impl<'a> Display for Forwarded<'a> { impl<'a> Display for Forwarded<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
let mut needs_delim = false; let mut needs_delim = false;
if let Some(ident) = &self.forwarded_for { if let Some(ident) = &self.forwarded_for {
if ident.display_needs_quote() { if ident.display_needs_quote() {
@ -248,7 +255,7 @@ impl<'a> NodeIdentifier<'a> {
} }
impl<'a> Display for NodeIdentifier<'a> { impl<'a> Display for NodeIdentifier<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self.port { match self.port {
Some(port) => write!(f, "{}:{}", self.name, port), Some(port) => write!(f, "{}:{}", self.name, port),
None => write!(f, "{}", self.name), None => write!(f, "{}", self.name),
@ -376,7 +383,7 @@ impl<'a> NodeName<'a> {
} }
impl<'a> Display for NodeName<'a> { impl<'a> Display for NodeName<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self { match self {
NodeName::Ip(IpAddr::V4(ip)) => write!(f, "{}", ip), NodeName::Ip(IpAddr::V4(ip)) => write!(f, "{}", ip),
NodeName::Ip(IpAddr::V6(ip)) => write!(f, "[{}]", ip), NodeName::Ip(IpAddr::V6(ip)) => write!(f, "[{}]", ip),