Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion book/text/book.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[book]
authors = ["Ryan Goodfellow"]
language = "en"
multilingual = false
src = "src"
title = "The x4c Book"

Expand Down
24 changes: 12 additions & 12 deletions book/text/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -196,35 +196,35 @@

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

{{#next}}
<a rel="next prefetch" href="{{ path_to_root }}{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
{{#if next}}
<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">
<i class="fa fa-angle-right"></i>
</a>
{{/next}}
{{/if}}

<div style="clear: both"></div>
</nav>
</div>
</div>

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

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

</div>
Expand Down
10 changes: 5 additions & 5 deletions codegen/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ pub fn emit(
// On failure write generated code to a tempfile
println!("Code generation produced unparsable code");
write_to_tempfile(&tokens)?;
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to parse generated code: {:?}", e),
));
return Err(io::Error::other(format!(
"Failed to parse generated code: {:?}",
e
)));
}
};
fs::write(filename, prettyplease::unparse(&f))?;
Expand Down Expand Up @@ -299,7 +299,7 @@ fn type_size(ty: &Type, ast: &AST) -> usize {
fn type_size_bytes(ty: &Type, ast: &AST) -> usize {
let s = type_size(ty, ast);
let mut b = s >> 3;
if s % 8 != 0 {
if !s.is_multiple_of(8) {
b += 1
}
b
Expand Down
2 changes: 1 addition & 1 deletion lang/p4rs/src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn udp6_checksum(data: &[u8]) -> u16 {
csum.add(payload_len[0], payload_len[1]);

let len = payload.len();
let (odd, len) = if len % 2 == 0 {
let (odd, len) = if len.is_multiple_of(2) {
(false, len)
} else {
(true, len - 1)
Expand Down
2 changes: 1 addition & 1 deletion lang/p4rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ pub fn extract_bit_action_parameter(
size: usize,
) -> BitVec<u8, Msb0> {
let mut byte_size = size >> 3;
if size % 8 != 0 {
if !size.is_multiple_of(8) {
byte_size += 1;
}
let mut b: BitVec<u8, Msb0> =
Expand Down
11 changes: 4 additions & 7 deletions lang/p4rs/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,16 @@ impl Key {
}
}

#[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)]
#[derive(
Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize, Default,
)]
pub enum Ternary {
#[default]
DontCare,
Value(BigUintKey),
Masked(BigUint, BigUint, usize),
}

impl Default for Ternary {
fn default() -> Self {
Self::DontCare
}
}

#[derive(Debug, Clone, PartialEq, Hash, Eq, Serialize, Deserialize)]
pub struct Prefix {
pub addr: IpAddr,
Expand Down
5 changes: 4 additions & 1 deletion p4/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ impl AST {
self.parsers.iter().find(|&p| p.name == name)
}

pub fn get_user_defined_type(&self, name: &str) -> Option<UserDefinedType> {
pub fn get_user_defined_type(
&self,
name: &str,
) -> Option<UserDefinedType<'_>> {
if let Some(user_struct) = self.get_struct(name) {
return Some(UserDefinedType::Struct(user_struct));
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.86.0"
channel = "1.92.0"
profile = "default"