diff --git a/Cargo.toml b/Cargo.toml index 748aa34..90e9af5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,10 @@ publish = false all-features = true rustdoc-args = ["--cfg", "docsrs"] +[features] +default = ["std"] +std = ["html-escape/std"] + [dependencies] html-escape = { version = "0.2", default-features = false } diff --git a/src/attributes.rs b/src/attributes.rs index 2d6c1ed..9564836 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; +use alloc::{borrow::Cow, string::String}; use crate::Attribute; diff --git a/src/elements.rs b/src/elements.rs index 780a3ef..3271c48 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; +use alloc::{borrow::Cow, string::String, vec::Vec}; use crate::{Attribute, Element, ElementInner}; diff --git a/src/lib.rs b/src/lib.rs index 5eaaa9c..f5d929d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,12 @@ +#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub mod attributes; pub mod elements; -use std::{borrow::Cow, fmt::Display}; +extern crate alloc; + +use alloc::{borrow::Cow, fmt::Display, vec::Vec}; #[derive(Debug, Clone)] pub struct Document(Element); @@ -49,7 +52,7 @@ impl Default for Document { } impl Display for Document { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result { write!(f, "\n{}", self.0) } } @@ -95,7 +98,7 @@ impl From for Element { } impl Display for Element { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result { match &self.0 { ElementInner::Parent { tag, @@ -128,9 +131,9 @@ impl Display for Element { } fn write_attributes( - f: &mut std::fmt::Formatter<'_>, + f: &mut alloc::fmt::Formatter<'_>, attributes: &Vec, -) -> Result<(), std::fmt::Error> { +) -> Result<(), alloc::fmt::Error> { for attribute in attributes { match &attribute.value { AttributeValue::String(s) => write!(