Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use <[T]>::split_at_checked instead of two separate get calls #64

Merged
merged 2 commits into from
Jul 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- os: ubuntu-latest
# MSRV. Not considered breaking when this has to be bumped.
# But update `rust-version` in `Cargo.toml`
rust: 1.77.0
rust: 1.80.0
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
description = "Tunnel UDP traffic inside a TCP stream. Each datagram is prefixed with a 16 bit unsigned integer containing the length"
repository = "https://github.com/mullvad/udp-over-tcp"
edition = "2021"
rust-version = "1.77.0"
rust-version = "1.80.0"
publish = false

[[bin]]
Expand Down
7 changes: 1 addition & 6 deletions src/forward_traffic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ fn split_first_datagram(buffer: &[u8]) -> Option<(&[u8], &[u8])> {
let (header, tail) = buffer.split_first_chunk::<HEADER_LEN>()?;
let datagram_len = usize::from(u16::from_be_bytes(*header));

// TODO: These two get calls (and thus double bounds check) can be replaced with
// `split_at_checked` when stabilized: https://github.com/rust-lang/rust/issues/119128
let datagram_data = tail.get(..datagram_len)?;
let tail = tail.get(datagram_len..)?;

Some((datagram_data, tail))
tail.split_at_checked(datagram_len)
}

/// Reads datagrams from `udp_in` and writes them (with the 16 bit header containing the length)
Expand Down
Loading