Skip to content

Commit

Permalink
Merge pull request #481 from dralley/msrv
Browse files Browse the repository at this point in the history
Remove use of `const fn`, add CI tests for MSRV
  • Loading branch information
Mingun committed Sep 20, 2022
2 parents da5f1e7 + b8cdc1f commit 240f204
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 32 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/rust.yml
Expand Up @@ -10,6 +10,13 @@ jobs:
- name: Check fmt
run: cargo fmt -- --check

msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.46.0
- run: cargo check

test:
strategy:
matrix:
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Expand Up @@ -10,13 +10,14 @@ repository = "https://github.com/tafia/quick-xml"
keywords = ["xml", "serde", "parser", "writer", "html"]
categories = ["asynchronous", "encoding", "parsing", "parser-implementations"]
license = "MIT"
rust-version = "1.46"

[dependencies]
document-features = { version = "0.2", optional = true }
encoding_rs = { version = "0.8", optional = true }
serde = { version = "1.0", optional = true }
tokio = { version = "1.21", optional = true, default-features = false, features = ["io-util"] }
memchr = "2.5"
serde = { version = "1.0.100", optional = true }
tokio = { version = "1.0", optional = true, default-features = false, features = ["io-util"] }
memchr = "2.0"

[dev-dependencies]
criterion = "0.4"
Expand Down
5 changes: 5 additions & 0 deletions Changelog.md
Expand Up @@ -16,6 +16,11 @@

### Misc Changes

- [#481]: Removed the uses of `const fn` added in version 0.24 in favor of a lower minimum
supported Rust version (1.46.0). Minimum supported Rust version is now verified in the CI.

[#481]: https://github.com/tafia/quick-xml/pull/481

## 0.25.0 -- 2022-09-10

### Bug Fixes
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -4,6 +4,7 @@
[![Crate](https://img.shields.io/crates/v/quick-xml.svg)](https://crates.io/crates/quick-xml)
[![docs.rs](https://docs.rs/quick-xml/badge.svg)](https://docs.rs/quick-xml)
[![codecov](https://img.shields.io/codecov/c/github/tafia/quick-xml)](https://codecov.io/gh/tafia/quick-xml)
[![MSRV](https://img.shields.io/badge/rustc-1.46.0+-ab6000.svg)](https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html)

High performance xml pull reader/writer.

Expand Down
2 changes: 1 addition & 1 deletion src/de/escape.rs
Expand Up @@ -25,7 +25,7 @@ pub struct EscapedDeserializer<'a> {
}

impl<'a> EscapedDeserializer<'a> {
pub const fn new(escaped_value: Cow<'a, [u8]>, decoder: Decoder, escaped: bool) -> Self {
pub fn new(escaped_value: Cow<'a, [u8]>, decoder: Decoder, escaped: bool) -> Self {
EscapedDeserializer {
decoder,
escaped_value,
Expand Down
2 changes: 1 addition & 1 deletion src/de/simple_type.rs
Expand Up @@ -546,7 +546,7 @@ impl<'de, 'a> SimpleTypeDeserializer<'de, 'a> {

/// Constructor for tests
#[inline]
const fn new(content: CowRef<'de, 'a>, escaped: bool, decoder: Decoder) -> Self {
fn new(content: CowRef<'de, 'a>, escaped: bool, decoder: Decoder) -> Self {
Self {
content,
escaped,
Expand Down
2 changes: 1 addition & 1 deletion src/encoding.rs
Expand Up @@ -61,7 +61,7 @@ impl Decoder {
///
/// [`decode`]: Self::decode
#[cfg(feature = "encoding")]
pub const fn encoding(&self) -> &'static Encoding {
pub fn encoding(&self) -> &'static Encoding {
self.encoding
}

Expand Down
4 changes: 2 additions & 2 deletions src/escapei.rs
Expand Up @@ -203,7 +203,7 @@ where
}

#[cfg(not(feature = "escape-html"))]
const fn named_entity(name: &str) -> Option<&str> {
fn named_entity(name: &str) -> Option<&str> {
// match over strings are not allowed in const functions
let s = match name.as_bytes() {
b"lt" => "<",
Expand All @@ -216,7 +216,7 @@ const fn named_entity(name: &str) -> Option<&str> {
Some(s)
}
#[cfg(feature = "escape-html")]
const fn named_entity(name: &str) -> Option<&str> {
fn named_entity(name: &str) -> Option<&str> {
// imported from https://dev.w3.org/html5/html-author/charref
// match over strings are not allowed in const functions
//TODO: automate up-to-dating using https://html.spec.whatwg.org/entities.json
Expand Down
12 changes: 6 additions & 6 deletions src/events/attributes.rs
Expand Up @@ -191,20 +191,20 @@ pub struct Attributes<'a> {
impl<'a> Attributes<'a> {
/// Internal constructor, used by `BytesStart`. Supplies data in reader's encoding
#[inline]
pub(crate) const fn wrap(buf: &'a [u8], pos: usize, html: bool) -> Self {
pub(crate) fn wrap(buf: &'a [u8], pos: usize, html: bool) -> Self {
Self {
bytes: buf,
state: IterState::new(pos, html),
}
}

/// Creates a new attribute iterator from a buffer.
pub const fn new(buf: &'a str, pos: usize) -> Self {
pub fn new(buf: &'a str, pos: usize) -> Self {
Self::wrap(buf.as_bytes(), pos, false)
}

/// Creates a new attribute iterator from a buffer, allowing HTML attribute syntax.
pub const fn html(buf: &'a str, pos: usize) -> Self {
pub fn html(buf: &'a str, pos: usize) -> Self {
Self::wrap(buf.as_bytes(), pos, true)
}

Expand Down Expand Up @@ -412,7 +412,7 @@ impl<T> Attr<T> {
impl<'a> Attr<&'a [u8]> {
/// Returns the key value
#[inline]
pub const fn key(&self) -> QName<'a> {
pub fn key(&self) -> QName<'a> {
QName(match self {
Attr::DoubleQ(key, _) => key,
Attr::SingleQ(key, _) => key,
Expand All @@ -425,7 +425,7 @@ impl<'a> Attr<&'a [u8]> {
///
/// [HTML specification]: https://www.w3.org/TR/2012/WD-html-markup-20120329/syntax.html#syntax-attr-empty
#[inline]
pub const fn value(&self) -> &'a [u8] {
pub fn value(&self) -> &'a [u8] {
match self {
Attr::DoubleQ(_, value) => value,
Attr::SingleQ(_, value) => value,
Expand Down Expand Up @@ -514,7 +514,7 @@ pub(crate) struct IterState {
}

impl IterState {
pub const fn new(offset: usize, html: bool) -> Self {
pub fn new(offset: usize, html: bool) -> Self {
Self {
state: State::Next(offset),
html,
Expand Down
6 changes: 3 additions & 3 deletions src/events/mod.rs
Expand Up @@ -72,7 +72,7 @@ pub struct BytesStart<'a> {
impl<'a> BytesStart<'a> {
/// Internal constructor, used by `Reader`. Supplies data in reader's encoding
#[inline]
pub(crate) const fn wrap(content: &'a [u8], name_len: usize) -> Self {
pub(crate) fn wrap(content: &'a [u8], name_len: usize) -> Self {
BytesStart {
buf: Cow::Borrowed(content),
name_len,
Expand Down Expand Up @@ -344,7 +344,7 @@ impl<'a> BytesDecl<'a> {
}

/// Creates a `BytesDecl` from a `BytesStart`
pub const fn from_start(start: BytesStart<'a>) -> Self {
pub fn from_start(start: BytesStart<'a>) -> Self {
Self { content: start }
}

Expand Down Expand Up @@ -549,7 +549,7 @@ pub struct BytesEnd<'a> {
impl<'a> BytesEnd<'a> {
/// Internal constructor, used by `Reader`. Supplies data in reader's encoding
#[inline]
pub(crate) const fn wrap(name: Cow<'a, [u8]>) -> Self {
pub(crate) fn wrap(name: Cow<'a, [u8]>) -> Self {
BytesEnd { name }
}

Expand Down
8 changes: 4 additions & 4 deletions src/name.rs
Expand Up @@ -21,7 +21,7 @@ pub struct QName<'a>(pub &'a [u8]);
impl<'a> QName<'a> {
/// Converts this name to an internal slice representation.
#[inline(always)]
pub const fn into_inner(self) -> &'a [u8] {
pub fn into_inner(self) -> &'a [u8] {
self.0
}

Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct LocalName<'a>(&'a [u8]);
impl<'a> LocalName<'a> {
/// Converts this name to an internal slice representation.
#[inline(always)]
pub const fn into_inner(self) -> &'a [u8] {
pub fn into_inner(self) -> &'a [u8] {
self.0
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ pub struct Prefix<'a>(&'a [u8]);
impl<'a> Prefix<'a> {
/// Extracts internal slice
#[inline(always)]
pub const fn into_inner(self) -> &'a [u8] {
pub fn into_inner(self) -> &'a [u8] {
self.0
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ impl<'a> Namespace<'a> {
/// [non-normalized]: https://www.w3.org/TR/REC-xml/#AVNormalize
/// [IRI reference]: https://datatracker.ietf.org/doc/html/rfc3987
#[inline(always)]
pub const fn into_inner(self) -> &'a [u8] {
pub fn into_inner(self) -> &'a [u8] {
self.0
}
//TODO: implement value normalization and use it when comparing namespaces
Expand Down
12 changes: 6 additions & 6 deletions src/reader/mod.rs
Expand Up @@ -377,7 +377,7 @@ enum EncodingRef {
#[cfg(feature = "encoding")]
impl EncodingRef {
#[inline]
const fn encoding(&self) -> &'static Encoding {
fn encoding(&self) -> &'static Encoding {
match self {
Self::Implicit(e) => e,
Self::Explicit(e) => e,
Expand All @@ -386,7 +386,7 @@ impl EncodingRef {
}
}
#[inline]
const fn can_be_refined(&self) -> bool {
fn can_be_refined(&self) -> bool {
match self {
Self::Implicit(_) | Self::BomDetected(_) => true,
Self::Explicit(_) | Self::XmlDetected(_) => false,
Expand Down Expand Up @@ -531,7 +531,7 @@ impl<R> Reader<R> {
}

/// Gets a reference to the underlying reader.
pub const fn get_ref(&self) -> &R {
pub fn get_ref(&self) -> &R {
&self.reader
}

Expand All @@ -543,7 +543,7 @@ impl<R> Reader<R> {
/// Gets the current byte position in the input data.
///
/// Useful when debugging errors.
pub const fn buffer_position(&self) -> usize {
pub fn buffer_position(&self) -> usize {
// when internal state is OpenedTag, we have actually read until '<',
// which we don't want to show
if let ParseState::OpenedTag = self.parser.state {
Expand All @@ -561,7 +561,7 @@ impl<R> Reader<R> {
/// If `encoding` feature is enabled and no encoding is specified in declaration,
/// defaults to UTF-8.
#[inline]
pub const fn decoder(&self) -> Decoder {
pub fn decoder(&self) -> Decoder {
self.parser.decoder()
}
}
Expand Down Expand Up @@ -848,7 +848,7 @@ impl ReadElementState {

/// A function to check whether the byte is a whitespace (blank, new line, carriage return or tab)
#[inline]
pub(crate) const fn is_whitespace(b: u8) -> bool {
pub(crate) fn is_whitespace(b: u8) -> bool {
match b {
b' ' | b'\r' | b'\n' | b'\t' => true,
_ => false,
Expand Down
2 changes: 1 addition & 1 deletion src/reader/parser.rs
Expand Up @@ -236,7 +236,7 @@ impl Parser {
///
/// If `encoding` feature is enabled and no encoding is specified in declaration,
/// defaults to UTF-8.
pub const fn decoder(&self) -> Decoder {
pub fn decoder(&self) -> Decoder {
Decoder {
#[cfg(feature = "encoding")]
encoding: self.encoding.encoding(),
Expand Down
2 changes: 1 addition & 1 deletion src/reader/slice_reader.rs
Expand Up @@ -353,7 +353,7 @@ mod test {
use crate::reader::XmlSource;

/// Default buffer constructor just pass the byte array from the test
const fn identity<T>(input: T) -> T {
fn identity<T>(input: T) -> T {
input
}

Expand Down
4 changes: 2 additions & 2 deletions src/se/mod.rs
Expand Up @@ -117,7 +117,7 @@ impl<'r, W: Write> Serializer<'r, W> {
/// Note, that attempt to serialize a non-struct (including unit structs
/// and newtype structs) will end up to an error. Use `with_root` to create
/// serializer with explicitly defined root element name
pub const fn new(writer: W) -> Self {
pub fn new(writer: W) -> Self {
Self::with_root(Writer::new(writer), None)
}

Expand Down Expand Up @@ -169,7 +169,7 @@ impl<'r, W: Write> Serializer<'r, W> {
/// r#"<root question="The Ultimate Question of Life, the Universe, and Everything" answer="42"/>"#
/// );
/// ```
pub const fn with_root(writer: Writer<W>, root_tag: Option<&'r str>) -> Self {
pub fn with_root(writer: Writer<W>, root_tag: Option<&'r str>) -> Self {
Self { writer, root_tag }
}

Expand Down
2 changes: 1 addition & 1 deletion src/writer.rs
Expand Up @@ -61,7 +61,7 @@ pub struct Writer<W: Write> {

impl<W: Write> Writer<W> {
/// Creates a `Writer` from a generic writer.
pub const fn new(inner: W) -> Writer<W> {
pub fn new(inner: W) -> Writer<W> {
Writer {
writer: inner,
indent: None,
Expand Down

0 comments on commit 240f204

Please sign in to comment.