Skip to content

Commit 44fb918

Browse files
committed
Drop const fn from places where it was previously added in 0.24
It makes the MSRV overly restrictive, and doesn't provide much benefit. Also add an MSRV check to the CI closes tafia#479
1 parent da5f1e7 commit 44fb918

16 files changed

+46
-32
lines changed

.github/workflows/rust.yml

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ jobs:
1010
- name: Check fmt
1111
run: cargo fmt -- --check
1212

13+
msrv:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: dtolnay/[email protected]
18+
- run: cargo check
19+
1320
test:
1421
strategy:
1522
matrix:

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ repository = "https://github.com/tafia/quick-xml"
1010
keywords = ["xml", "serde", "parser", "writer", "html"]
1111
categories = ["asynchronous", "encoding", "parsing", "parser-implementations"]
1212
license = "MIT"
13+
rust-version = "1.43.1"
1314

1415
[dependencies]
1516
document-features = { version = "0.2", optional = true }
1617
encoding_rs = { version = "0.8", optional = true }
17-
serde = { version = "1.0", optional = true }
18-
tokio = { version = "1.21", optional = true, default-features = false, features = ["io-util"] }
19-
memchr = "2.5"
18+
serde = { version = "1.0.100", optional = true }
19+
tokio = { version = "1.0", optional = true, default-features = false, features = ["io-util"] }
20+
memchr = "2.0"
2021

2122
[dev-dependencies]
2223
criterion = "0.4"

Changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
### Misc Changes
1818

19+
- [#481]: Removed the uses of `const fn` added in version 0.24 in favor of a lower minimum
20+
supported Rust version (1.43.1). Minimum supported Rust version is now verified in the CI.
21+
22+
[#481]: https://github.com/tafia/quick-xml/pull/481
23+
1924
## 0.25.0 -- 2022-09-10
2025

2126
### Bug Fixes

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Crate](https://img.shields.io/crates/v/quick-xml.svg)](https://crates.io/crates/quick-xml)
55
[![docs.rs](https://docs.rs/quick-xml/badge.svg)](https://docs.rs/quick-xml)
66
[![codecov](https://img.shields.io/codecov/c/github/tafia/quick-xml)](https://codecov.io/gh/tafia/quick-xml)
7+
[![MSRV](https://img.shields.io/badge/rustc-1.43.1+-ab6000.svg)](https://blog.rust-lang.org/2020/05/07/Rust.1.43.1.html)
78

89
High performance xml pull reader/writer.
910

src/de/escape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct EscapedDeserializer<'a> {
2525
}
2626

2727
impl<'a> EscapedDeserializer<'a> {
28-
pub const fn new(escaped_value: Cow<'a, [u8]>, decoder: Decoder, escaped: bool) -> Self {
28+
pub fn new(escaped_value: Cow<'a, [u8]>, decoder: Decoder, escaped: bool) -> Self {
2929
EscapedDeserializer {
3030
decoder,
3131
escaped_value,

src/de/simple_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'de, 'a> SimpleTypeDeserializer<'de, 'a> {
546546

547547
/// Constructor for tests
548548
#[inline]
549-
const fn new(content: CowRef<'de, 'a>, escaped: bool, decoder: Decoder) -> Self {
549+
fn new(content: CowRef<'de, 'a>, escaped: bool, decoder: Decoder) -> Self {
550550
Self {
551551
content,
552552
escaped,

src/encoding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Decoder {
6161
///
6262
/// [`decode`]: Self::decode
6363
#[cfg(feature = "encoding")]
64-
pub const fn encoding(&self) -> &'static Encoding {
64+
pub fn encoding(&self) -> &'static Encoding {
6565
self.encoding
6666
}
6767

src/escapei.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ where
203203
}
204204

205205
#[cfg(not(feature = "escape-html"))]
206-
const fn named_entity(name: &str) -> Option<&str> {
206+
fn named_entity(name: &str) -> Option<&str> {
207207
// match over strings are not allowed in const functions
208208
let s = match name.as_bytes() {
209209
b"lt" => "<",
@@ -216,7 +216,7 @@ const fn named_entity(name: &str) -> Option<&str> {
216216
Some(s)
217217
}
218218
#[cfg(feature = "escape-html")]
219-
const fn named_entity(name: &str) -> Option<&str> {
219+
fn named_entity(name: &str) -> Option<&str> {
220220
// imported from https://dev.w3.org/html5/html-author/charref
221221
// match over strings are not allowed in const functions
222222
//TODO: automate up-to-dating using https://html.spec.whatwg.org/entities.json

src/events/attributes.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,20 @@ pub struct Attributes<'a> {
191191
impl<'a> Attributes<'a> {
192192
/// Internal constructor, used by `BytesStart`. Supplies data in reader's encoding
193193
#[inline]
194-
pub(crate) const fn wrap(buf: &'a [u8], pos: usize, html: bool) -> Self {
194+
pub(crate) fn wrap(buf: &'a [u8], pos: usize, html: bool) -> Self {
195195
Self {
196196
bytes: buf,
197197
state: IterState::new(pos, html),
198198
}
199199
}
200200

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

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

@@ -412,7 +412,7 @@ impl<T> Attr<T> {
412412
impl<'a> Attr<&'a [u8]> {
413413
/// Returns the key value
414414
#[inline]
415-
pub const fn key(&self) -> QName<'a> {
415+
pub fn key(&self) -> QName<'a> {
416416
QName(match self {
417417
Attr::DoubleQ(key, _) => key,
418418
Attr::SingleQ(key, _) => key,
@@ -425,7 +425,7 @@ impl<'a> Attr<&'a [u8]> {
425425
///
426426
/// [HTML specification]: https://www.w3.org/TR/2012/WD-html-markup-20120329/syntax.html#syntax-attr-empty
427427
#[inline]
428-
pub const fn value(&self) -> &'a [u8] {
428+
pub fn value(&self) -> &'a [u8] {
429429
match self {
430430
Attr::DoubleQ(_, value) => value,
431431
Attr::SingleQ(_, value) => value,
@@ -514,7 +514,7 @@ pub(crate) struct IterState {
514514
}
515515

516516
impl IterState {
517-
pub const fn new(offset: usize, html: bool) -> Self {
517+
pub fn new(offset: usize, html: bool) -> Self {
518518
Self {
519519
state: State::Next(offset),
520520
html,

src/events/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub struct BytesStart<'a> {
7272
impl<'a> BytesStart<'a> {
7373
/// Internal constructor, used by `Reader`. Supplies data in reader's encoding
7474
#[inline]
75-
pub(crate) const fn wrap(content: &'a [u8], name_len: usize) -> Self {
75+
pub(crate) fn wrap(content: &'a [u8], name_len: usize) -> Self {
7676
BytesStart {
7777
buf: Cow::Borrowed(content),
7878
name_len,
@@ -344,7 +344,7 @@ impl<'a> BytesDecl<'a> {
344344
}
345345

346346
/// Creates a `BytesDecl` from a `BytesStart`
347-
pub const fn from_start(start: BytesStart<'a>) -> Self {
347+
pub fn from_start(start: BytesStart<'a>) -> Self {
348348
Self { content: start }
349349
}
350350

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

src/name.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct QName<'a>(pub &'a [u8]);
2121
impl<'a> QName<'a> {
2222
/// Converts this name to an internal slice representation.
2323
#[inline(always)]
24-
pub const fn into_inner(self) -> &'a [u8] {
24+
pub fn into_inner(self) -> &'a [u8] {
2525
self.0
2626
}
2727

@@ -138,7 +138,7 @@ pub struct LocalName<'a>(&'a [u8]);
138138
impl<'a> LocalName<'a> {
139139
/// Converts this name to an internal slice representation.
140140
#[inline(always)]
141-
pub const fn into_inner(self) -> &'a [u8] {
141+
pub fn into_inner(self) -> &'a [u8] {
142142
self.0
143143
}
144144
}
@@ -188,7 +188,7 @@ pub struct Prefix<'a>(&'a [u8]);
188188
impl<'a> Prefix<'a> {
189189
/// Extracts internal slice
190190
#[inline(always)]
191-
pub const fn into_inner(self) -> &'a [u8] {
191+
pub fn into_inner(self) -> &'a [u8] {
192192
self.0
193193
}
194194
}
@@ -253,7 +253,7 @@ impl<'a> Namespace<'a> {
253253
/// [non-normalized]: https://www.w3.org/TR/REC-xml/#AVNormalize
254254
/// [IRI reference]: https://datatracker.ietf.org/doc/html/rfc3987
255255
#[inline(always)]
256-
pub const fn into_inner(self) -> &'a [u8] {
256+
pub fn into_inner(self) -> &'a [u8] {
257257
self.0
258258
}
259259
//TODO: implement value normalization and use it when comparing namespaces

src/reader/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ enum EncodingRef {
377377
#[cfg(feature = "encoding")]
378378
impl EncodingRef {
379379
#[inline]
380-
const fn encoding(&self) -> &'static Encoding {
380+
fn encoding(&self) -> &'static Encoding {
381381
match self {
382382
Self::Implicit(e) => e,
383383
Self::Explicit(e) => e,
@@ -386,7 +386,7 @@ impl EncodingRef {
386386
}
387387
}
388388
#[inline]
389-
const fn can_be_refined(&self) -> bool {
389+
fn can_be_refined(&self) -> bool {
390390
match self {
391391
Self::Implicit(_) | Self::BomDetected(_) => true,
392392
Self::Explicit(_) | Self::XmlDetected(_) => false,
@@ -531,7 +531,7 @@ impl<R> Reader<R> {
531531
}
532532

533533
/// Gets a reference to the underlying reader.
534-
pub const fn get_ref(&self) -> &R {
534+
pub fn get_ref(&self) -> &R {
535535
&self.reader
536536
}
537537

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

849849
/// A function to check whether the byte is a whitespace (blank, new line, carriage return or tab)
850850
#[inline]
851-
pub(crate) const fn is_whitespace(b: u8) -> bool {
851+
pub(crate) fn is_whitespace(b: u8) -> bool {
852852
match b {
853853
b' ' | b'\r' | b'\n' | b'\t' => true,
854854
_ => false,

src/reader/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl Parser {
236236
///
237237
/// If `encoding` feature is enabled and no encoding is specified in declaration,
238238
/// defaults to UTF-8.
239-
pub const fn decoder(&self) -> Decoder {
239+
pub fn decoder(&self) -> Decoder {
240240
Decoder {
241241
#[cfg(feature = "encoding")]
242242
encoding: self.encoding.encoding(),

src/reader/slice_reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mod test {
353353
use crate::reader::XmlSource;
354354

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

src/se/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'r, W: Write> Serializer<'r, W> {
117117
/// Note, that attempt to serialize a non-struct (including unit structs
118118
/// and newtype structs) will end up to an error. Use `with_root` to create
119119
/// serializer with explicitly defined root element name
120-
pub const fn new(writer: W) -> Self {
120+
pub fn new(writer: W) -> Self {
121121
Self::with_root(Writer::new(writer), None)
122122
}
123123

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

src/writer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct Writer<W: Write> {
6161

6262
impl<W: Write> Writer<W> {
6363
/// Creates a `Writer` from a generic writer.
64-
pub const fn new(inner: W) -> Writer<W> {
64+
pub fn new(inner: W) -> Writer<W> {
6565
Writer {
6666
writer: inner,
6767
indent: None,

0 commit comments

Comments
 (0)