Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Rust 2021 edition, add no_std support #17

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Copy link
Member

@DJMcNab DJMcNab Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems suspect, but isn't needed to be fixed in this PR.

#![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;

Expand Down Expand Up @@ -126,6 +130,7 @@ impl fmt::Display for Error {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

Only need to wait two more years for core::error::Error at this pace of MSRV growth


/// A position in text.
Expand Down
3 changes: 2 additions & 1 deletion src/selector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt;
use alloc::{vec, vec::Vec};
use core::fmt;

use log::warn;

Expand Down
4 changes: 2 additions & 2 deletions src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str;
use core::str;

use crate::{Error, TextPos};

Expand Down Expand Up @@ -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()
}

Expand Down
Loading