Skip to content

Commit 569a3a1

Browse files
committed
chore: update to rust 2024 edition
1 parent 662e7dc commit 569a3a1

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ env:
1111
jobs:
1212
style:
1313
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
rust: ["1.85.0", stable, beta]
1417
steps:
1518
- name: Checkout
1619
uses: actions/checkout@v2
1720
- name: Install rust
1821
uses: actions-rs/toolchain@v1
1922
with:
20-
toolchain: stable
23+
toolchain: ${{ matrix.rust }}
2124
components: rustfmt
2225
default: true
2326
- name: cargo fmt -- --check

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ homepage = "https://github.com/Roguelazer/rust-syslog-rfc5424"
88
repository = "https://github.com/Roguelazer/rust-syslog-rfc5424"
99
license = "ISC"
1010
readme = "README.md"
11-
edition = "2018"
11+
edition = "2024"
1212

1313
[dependencies]
1414
time = "0.3"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This tool supports serializing the parsed messages using serde if it's built wit
88

99
This library is licensed under the ISC license, a copy of which can be found in [LICENSE.txt](LICENSE.txt)
1010

11-
The minimum supported Rust version for this library is 1.34.
11+
The minimum supported Rust version for this library is 1.85.
1212

1313
## Performance
1414

src/message.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub enum ProcId {
3131
impl PartialOrd for ProcId {
3232
fn partial_cmp(&self, other: &ProcId) -> Option<Ordering> {
3333
match (self, other) {
34-
(&ProcId::PID(ref s_p), &ProcId::PID(ref o_p)) => Some(s_p.cmp(o_p)),
35-
(&ProcId::Name(ref s_n), &ProcId::Name(ref o_n)) => Some(s_n.cmp(o_n)),
34+
(ProcId::PID(s_p), ProcId::PID(o_p)) => Some(s_p.cmp(o_p)),
35+
(ProcId::Name(s_n), ProcId::Name(o_n)) => Some(s_n.cmp(o_n)),
3636
_ => None,
3737
}
3838
}
@@ -95,9 +95,7 @@ impl StructuredData {
9595
where
9696
SI: Into<SDIDType>,
9797
{
98-
self.elements
99-
.entry(sd_id.into())
100-
.or_insert_with(BTreeMap::new)
98+
self.elements.entry(sd_id.into()).or_default()
10199
}
102100

103101
/// Insert a new (sd_id, sd_param_id) -> sd_value mapping into the StructuredData
@@ -227,8 +225,10 @@ mod tests {
227225
let encoded = serde_json::to_string(&m).expect("Should encode to JSON");
228226
// XXX: we don't have a guaranteed order, I don't think, so this might break with minor
229227
// version changes. *shrug*
230-
assert_eq!(encoded,
231-
"{\"severity\":\"info\",\"facility\":\"kern\",\"version\":1,\"timestamp\":null,\"timestamp_nanos\":null,\"hostname\":null,\"appname\":null,\"procid\":null,\"msgid\":null,\"sd\":{},\"msg\":\"\"}");
228+
assert_eq!(
229+
encoded,
230+
"{\"severity\":\"info\",\"facility\":\"kern\",\"version\":1,\"timestamp\":null,\"timestamp_nanos\":null,\"hostname\":null,\"appname\":null,\"procid\":null,\"msgid\":null,\"sd\":{},\"msg\":\"\"}"
231+
);
232232
}
233233

234234
#[test]

src/parser.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn parse_sd_id(input: &str) -> ParseResult<(String, &str)> {
117117
}
118118

119119
/** Parse a `param_value`... a.k.a. a quoted string */
120-
fn parse_param_value(input: &str) -> ParseResult<(Cow<str>, &str)> {
120+
fn parse_param_value(input: &'_ str) -> ParseResult<(Cow<'_, str>, &'_ str)> {
121121
let mut rest = input;
122122
take_char!(rest, '"');
123123
// Can't do a 0-copy &str slice here because we need to un-escape escaped quotes
@@ -162,17 +162,16 @@ fn parse_sd_params(input: &str) -> ParseResult<(ParsedSDParams, &str)> {
162162
let mut params = Vec::new();
163163
let mut top = input;
164164
loop {
165-
if let Some(rest2) = maybe_expect_char!(top, ' ') {
166-
let mut rest = rest2;
167-
let param_name = take_item!(parse_sd_id(rest), rest);
168-
take_char!(rest, '=');
169-
let param_value = take_item!(parse_param_value(rest), rest);
170-
// is there an uglier modifier than &*
171-
params.push((param_name, String::from(&*param_value)));
172-
top = rest;
173-
} else {
165+
let Some(rest2) = maybe_expect_char!(top, ' ') else {
174166
return Ok((params, top));
175-
}
167+
};
168+
let mut rest = rest2;
169+
let param_name = take_item!(parse_sd_id(rest), rest);
170+
take_char!(rest, '=');
171+
let param_value = take_item!(parse_param_value(rest), rest);
172+
// is there an uglier modifier than &*
173+
params.push((param_name, String::from(&*param_value)));
174+
top = rest;
176175
}
177176
}
178177

@@ -212,7 +211,7 @@ fn parse_pri_val(pri: i32) -> ParseResult<(severity::SyslogSeverity, facility::S
212211

213212
/// Parse an i32
214213
fn parse_num(s: &str, min_digits: usize, max_digits: usize) -> ParseResult<(i32, &str)> {
215-
let (res, rest1) = take_while(s, |c| ('0'..='9').contains(&c), max_digits);
214+
let (res, rest1) = take_while(s, |c| c.is_ascii_digit(), max_digits);
216215
let rest = rest1.ok_or(ParseErr::UnexpectedEndOfInput)?;
217216
if res.len() < min_digits {
218217
Err(ParseErr::TooFewDigits)
@@ -231,7 +230,7 @@ fn parse_num_generic<NT>(s: &str, min_digits: usize, max_digits: usize) -> Parse
231230
where
232231
NT: FromStr<Err = num::ParseIntError>,
233232
{
234-
let (res, rest1) = take_while(s, |c| ('0'..='9').contains(&c), max_digits);
233+
let (res, rest1) = take_while(s, |c| c.is_ascii_digit(), max_digits);
235234
let rest = rest1.ok_or(ParseErr::UnexpectedEndOfInput)?;
236235
if res.len() < min_digits {
237236
Err(ParseErr::TooFewDigits)
@@ -411,7 +410,7 @@ mod tests {
411410
use std::collections::BTreeMap;
412411
use std::mem;
413412

414-
use super::{parse_message, ParseErr};
413+
use super::{ParseErr, parse_message};
415414
use crate::message;
416415

417416
use crate::facility::SyslogFacility;
@@ -427,7 +426,7 @@ mod tests {
427426
assert!(msg.appname.is_none());
428427
assert!(msg.procid.is_none());
429428
assert!(msg.msgid.is_none());
430-
assert!(msg.sd.len() == 0);
429+
assert!(msg.sd.is_empty());
431430
}
432431

433432
#[test]

0 commit comments

Comments
 (0)