diff --git a/Cargo.toml b/Cargo.toml index 2351c63..fd5454c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,15 @@ description = "A simple CSS 2 parser and selector." repository = "https://github.com/RazrFalcon/simplecss" keywords = ["css", "parser", "selector"] categories = ["parser-implementations"] -edition = "2018" +edition = "2021" exclude = ["testing-tools/**"] +[features] +default = ["std"] +std = ["log/std"] + [dependencies] -log = "0.4.8" +log = { version = "0.4.8", default-features = false } [dev-dependencies] env_logger = { version = "0.6", default-features = false } diff --git a/src/lib.rs b/src/lib.rs index 2bd0a64..4171681 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,10 +27,14 @@ Since it's very simple we will start with limitations: */ #![doc(html_root_url = "https://docs.rs/simplecss/0.2.1")] +#![cfg_attr(all(not(feature = "std"), not(test)), no_std)] #![forbid(unsafe_code)] #![warn(missing_docs)] -use std::fmt; +extern crate alloc; + +use alloc::vec::Vec; +use core::fmt; use log::warn; @@ -126,6 +130,7 @@ impl fmt::Display for Error { } } +#[cfg(feature = "std")] impl std::error::Error for Error {} /// A position in text. diff --git a/src/selector.rs b/src/selector.rs index 3815813..c6575b6 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -1,4 +1,5 @@ -use std::fmt; +use alloc::{vec, vec::Vec}; +use core::fmt; use log::warn; diff --git a/src/stream.rs b/src/stream.rs index 80eb889..006afcd 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -1,4 +1,4 @@ -use std::str; +use core::str; use crate::{Error, TextPos}; @@ -284,7 +284,7 @@ impl<'a> Stream<'a> { #[inline(never)] pub fn gen_text_pos_from(&self, pos: usize) -> TextPos { let mut s = *self; - s.pos = std::cmp::min(pos, self.text.len()); + s.pos = core::cmp::min(pos, self.text.len()); s.gen_text_pos() }