Skip to content

Commit 33d6460

Browse files
authored
Rust 1.92 (#211)
1 parent e476706 commit 33d6460

8 files changed

Lines changed: 28 additions & 29 deletions

File tree

book/text/book.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[book]
22
authors = ["Ryan Goodfellow"]
33
language = "en"
4-
multilingual = false
54
src = "src"
65
title = "The x4c Book"
76

book/text/theme/index.hbs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,35 +196,35 @@
196196

197197
<nav class="nav-wrapper" aria-label="Page navigation">
198198
<!-- Mobile navigation buttons -->
199-
{{#previous}}
200-
<a rel="prev" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
199+
{{#if previous}}
200+
<a rel="prev" href="{{ path_to_root }}{{previous.link}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
201201
<i class="fa fa-angle-left"></i>
202202
</a>
203-
{{/previous}}
203+
{{/if}}
204204

205-
{{#next}}
206-
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
205+
{{#if next}}
206+
<a rel="next prefetch" href="{{ path_to_root }}{{next.link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
207207
<i class="fa fa-angle-right"></i>
208208
</a>
209-
{{/next}}
209+
{{/if}}
210210

211211
<div style="clear: both"></div>
212212
</nav>
213213
</div>
214214
</div>
215215

216216
<nav class="nav-wide-wrapper" aria-label="Page navigation">
217-
{{#previous}}
218-
<a rel="prev" href="{{ path_to_root }}{{link}}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
217+
{{#if previous}}
218+
<a rel="prev" href="{{ path_to_root }}{{previous.link}}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
219219
<i class="fa fa-angle-left"></i>
220220
</a>
221-
{{/previous}}
221+
{{/if}}
222222

223-
{{#next}}
224-
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
223+
{{#if next}}
224+
<a rel="next prefetch" href="{{ path_to_root }}{{next.link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
225225
<i class="fa fa-angle-right"></i>
226226
</a>
227-
{{/next}}
227+
{{/if}}
228228
</nav>
229229

230230
</div>

codegen/rust/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ pub fn emit(
101101
// On failure write generated code to a tempfile
102102
println!("Code generation produced unparsable code");
103103
write_to_tempfile(&tokens)?;
104-
return Err(io::Error::new(
105-
io::ErrorKind::Other,
106-
format!("Failed to parse generated code: {:?}", e),
107-
));
104+
return Err(io::Error::other(format!(
105+
"Failed to parse generated code: {:?}",
106+
e
107+
)));
108108
}
109109
};
110110
fs::write(filename, prettyplease::unparse(&f))?;
@@ -299,7 +299,7 @@ fn type_size(ty: &Type, ast: &AST) -> usize {
299299
fn type_size_bytes(ty: &Type, ast: &AST) -> usize {
300300
let s = type_size(ty, ast);
301301
let mut b = s >> 3;
302-
if s % 8 != 0 {
302+
if !s.is_multiple_of(8) {
303303
b += 1
304304
}
305305
b

lang/p4rs/src/checksum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn udp6_checksum(data: &[u8]) -> u16 {
6262
csum.add(payload_len[0], payload_len[1]);
6363

6464
let len = payload.len();
65-
let (odd, len) = if len % 2 == 0 {
65+
let (odd, len) = if len.is_multiple_of(2) {
6666
(false, len)
6767
} else {
6868
(true, len - 1)

lang/p4rs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub fn extract_bit_action_parameter(
370370
size: usize,
371371
) -> BitVec<u8, Msb0> {
372372
let mut byte_size = size >> 3;
373-
if size % 8 != 0 {
373+
if !size.is_multiple_of(8) {
374374
byte_size += 1;
375375
}
376376
let mut b: BitVec<u8, Msb0> =

lang/p4rs/src/table.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,16 @@ impl Key {
8383
}
8484
}
8585

86-
#[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)]
86+
#[derive(
87+
Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize, Default,
88+
)]
8789
pub enum Ternary {
90+
#[default]
8891
DontCare,
8992
Value(BigUintKey),
9093
Masked(BigUint, BigUint, usize),
9194
}
9295

93-
impl Default for Ternary {
94-
fn default() -> Self {
95-
Self::DontCare
96-
}
97-
}
98-
9996
#[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)]
10097
pub struct Prefix {
10198
pub addr: IpAddr,

p4/src/ast.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ impl AST {
4747
self.parsers.iter().find(|&p| p.name == name)
4848
}
4949

50-
pub fn get_user_defined_type(&self, name: &str) -> Option<UserDefinedType> {
50+
pub fn get_user_defined_type(
51+
&self,
52+
name: &str,
53+
) -> Option<UserDefinedType<'_>> {
5154
if let Some(user_struct) = self.get_struct(name) {
5255
return Some(UserDefinedType::Struct(user_struct));
5356
}

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.86.0"
2+
channel = "1.92.0"
33
profile = "default"

0 commit comments

Comments
 (0)