Skip to content

Commit 49ea03a

Browse files
authored
chore: update to rust 2024 edition (#27)
1 parent 98e0c7e commit 49ea03a

File tree

5 files changed

+45
-52
lines changed

5 files changed

+45
-52
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, main ]
66
pull_request:
77

88
env:
@@ -13,44 +13,38 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
17-
- name: Install rust
18-
uses: actions-rs/toolchain@v1
16+
uses: actions/checkout@v5
17+
- uses: dtolnay/rust-toolchain@stable
1918
with:
20-
toolchain: stable
21-
components: rustfmt
22-
default: true
23-
- name: cargo fmt -- --check
24-
uses: actions-rs/cargo@v1
25-
with:
26-
command: fmt
27-
args: --all -- --check
19+
components: rustfmt,clippy
20+
toolchain: 1.91.1
21+
- uses: Swatinem/rust-cache@v2
22+
- name: cargo fmt
23+
run: cargo fmt --all -- --check
24+
- name: cargo clippy
25+
run: cargo clippy -- -D warnings
2826
test:
2927
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
rust: ["1.85.0", stable, beta]
3031
steps:
31-
- uses: actions/checkout@v2
32-
- name: Install rust
33-
uses: actions-rs/toolchain@v1
32+
- uses: actions/checkout@v5
33+
- uses: dtolnay/rust-toolchain@stable
3434
with:
35-
toolchain: stable
36-
components: rustfmt
37-
default: true
35+
toolchain: ${{ matrix.rust }}
36+
- uses: Swatinem/rust-cache@v2
3837
- name: Test
39-
uses: actions-rs/cargo@v1
40-
with:
41-
command: test
38+
run: cargo test --all-features
4239
audit:
4340
runs-on: ubuntu-latest
4441
steps:
45-
- uses: actions/checkout@v2
46-
- name: Install rust
47-
uses: actions-rs/toolchain@v1
42+
- uses: actions/checkout@v5
43+
- uses: dtolnay/rust-toolchain@stable
4844
with:
4945
toolchain: stable
50-
components: rustfmt
51-
default: true
52-
- name: cargo audit
53-
uses: actions-rs/[email protected]
46+
- uses: taiki-e/install-action@v2
5447
with:
55-
token: ${{ secrets.GITHUB_TOKEN }}
48+
tool: cargo-audit
49+
- run: cargo audit
5650

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: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -412,7 +411,7 @@ mod tests {
412411
use std::collections::BTreeMap;
413412
use std::mem;
414413

415-
use super::{parse_message, ParseErr};
414+
use super::{ParseErr, parse_message};
416415
use crate::message;
417416

418417
use crate::facility::SyslogFacility;
@@ -428,7 +427,7 @@ mod tests {
428427
assert!(msg.appname.is_none());
429428
assert!(msg.procid.is_none());
430429
assert!(msg.msgid.is_none());
431-
assert!(msg.sd.len() == 0);
430+
assert!(msg.sd.is_empty());
432431
}
433432

434433
#[test]

0 commit comments

Comments
 (0)