Skip to content

Commit

Permalink
support no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz committed Nov 1, 2024
1 parent 7a16653 commit 260625b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;
use alloc::{borrow::Cow, string::String};

use crate::Attribute;

Expand Down
2 changes: 1 addition & 1 deletion src/elements.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;
use alloc::{borrow::Cow, string::String, vec::Vec};

use crate::{Attribute, Element, ElementInner};

Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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, "<!DOCTYPE html>\n{}", self.0)
}
}
Expand Down Expand Up @@ -95,7 +98,7 @@ impl From<ElementInner> 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,
Expand Down Expand Up @@ -128,9 +131,9 @@ impl Display for Element {
}

fn write_attributes(
f: &mut std::fmt::Formatter<'_>,
f: &mut alloc::fmt::Formatter<'_>,
attributes: &Vec<Attribute>,
) -> Result<(), std::fmt::Error> {
) -> Result<(), alloc::fmt::Error> {
for attribute in attributes {
match &attribute.value {
AttributeValue::String(s) => write!(
Expand Down

0 comments on commit 260625b

Please sign in to comment.