Skip to content

Commit 4bed9d6

Browse files
Move 'slice-rust' repository into the 'slicec' repo.
This PR completes the move by updating formatting, fixing various typos, and rewriting CI, so that both the 'slicec' and 'slice-codec' crates now live in the same repository.
1 parent 69dbfca commit 4bed9d6

File tree

17 files changed

+120
-532
lines changed

17 files changed

+120
-532
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: ci
22

33
on:
44
push:
@@ -7,68 +7,81 @@ on:
77
branches: [main]
88

99
env:
10+
WARNINGS_AS_ERRORS: yes
1011
CARGO_TERM_COLOR: always
1112

1213
jobs:
13-
build_and_test:
14+
slicec:
15+
strategy:
16+
fail-fast: false
1417
runs-on: ubuntu-latest
1518
timeout-minutes: 10
19+
20+
steps:
21+
- name: 📐 Setup
22+
run: rustup component add clippy
23+
- name: 📂 Checkout Repository
24+
uses: actions/checkout@v4
25+
- name: 🔨 Build
26+
run: cargo build --all-targets -p slicec
27+
- name: 🧪 Test
28+
run: cargo test -p slicec
29+
- name: 🔎 Lint
30+
run: cargo clippy --all-targets --no-deps -p slicec
31+
- name: 📚 Generate Documentation
32+
run: cargo doc --document-private-items --no-deps -p slicec
33+
env:
34+
RUSTDOCFLAGS: "-D warnings"
35+
36+
slice-codec:
1637
strategy:
1738
fail-fast: false
1839
matrix:
19-
features:
20-
[
21-
"",
22-
"alloc",
23-
"std",
24-
"tokio",
25-
"std,tokio",
26-
"slice2",
27-
"slice2,alloc",
28-
"slice2,std",
29-
"slice2,tokio",
30-
"slice2,std,tokio",
31-
]
40+
features: [
41+
"",
42+
"alloc",
43+
"std",
44+
"tokio",
45+
"slice2",
46+
"slice2,alloc",
47+
"slice2,std",
48+
"slice2,tokio",
49+
]
50+
runs-on: ubuntu-latest
51+
timeout-minutes: 10
52+
3253
steps:
33-
- name: 📦 Setup
34-
run: echo "FEATURES=${{ matrix.features && '--features ' || '' }}${{ matrix.features }}" >> $GITHUB_ENV
35-
- uses: actions/checkout@v4
36-
- name: 📦 Cache
37-
uses: actions/cache@v3
38-
with:
39-
path: |
40-
~/.cargo/bin/
41-
~/.cargo/registry/index/
42-
~/.cargo/registry/cache/
43-
~/.cargo/git/db/
44-
target/
45-
Cargo.lock
46-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
47-
restore-keys: |
48-
${{ runner.os }}-cargo-
49-
- name: 📦 Install
54+
- name: 📐 Setup
5055
run: |
56+
echo "FEATURES=${{ matrix.features && '--features ' || '' }}${{ matrix.features }}" >> $GITHUB_ENV
5157
rustup toolchain install nightly
5258
rustup component add clippy
5359
rustup component add miri --toolchain nightly
60+
- name: 📂 Checkout Repository
61+
uses: actions/checkout@v4
5462
- name: 🔨 Build
55-
run: cargo build --no-default-features $FEATURES
63+
run: cargo build --all-targets --no-default-features $FEATURES -p slice-codec
5664
- name: 🧪 Test
57-
run: cargo +nightly miri test --no-default-features $FEATURES
58-
- name: 📚 Docs
59-
run: cargo doc --no-deps --no-default-features --document-private-items $FEATURES
65+
run: cargo test --no-default-features $FEATURES -p slice-codec
66+
- name: 📋 Check Soundness
67+
run: cargo +nightly miri test --no-default-features $FEATURES -p slice-codec
6068
- name: 🔎 Lint
61-
run: cargo clippy --all-targets --no-default-features $FEATURES --no-deps
69+
run: cargo clippy --all-targets --no-default-features $FEATURES --no-deps -p slice-codec
70+
- name: 📚 Generate Documentation
71+
run: cargo doc --document-private-items --no-deps --no-default-features $FEATURES -p slice-codec
72+
env:
73+
RUSTDOCFLAGS: "-D warnings"
6274

6375
format:
6476
runs-on: ubuntu-latest
6577
timeout-minutes: 5
6678

6779
steps:
68-
- uses: actions/checkout@v3
69-
- name: 📦 Install nightly toolchain
80+
- name: 📂 Checkout Repository
81+
uses: actions/checkout@v4
82+
- name: 📐 Setup
7083
run: |
7184
rustup toolchain install nightly
7285
rustup component add rustfmt --toolchain nightly
73-
- name: 🔎 Format using rustfmt
86+
- name: 🔎 Check Formatting
7487
run: cargo +nightly fmt --check

.vscode/cspell.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": "0.2",
3-
"language": "en, lorem",
3+
"language": "en",
44
"words": [
55
"attributables",
66
"bools",
@@ -11,23 +11,18 @@
1111
"Commentable",
1212
"deduped",
1313
"deque",
14-
"dicant",
1514
"downcasted",
1615
"downcasting",
1716
"encodable",
18-
"explicari",
1917
"grcov",
2018
"Hashable",
2119
"Hasher",
2220
"icerpc",
2321
"lalrpop",
24-
"legimus",
2522
"MSRV",
2623
"nonoverlapping",
2724
"nonterminal",
2825
"peekable",
29-
"ponderum",
30-
"repudiare",
3126
"rfind",
3227
"rsplit",
3328
"RUSTDOCFLAGS",
@@ -54,7 +49,6 @@
5449
"misc",
5550
"en_US",
5651
"rust",
57-
"softwareTerms",
58-
"lorem"
52+
"softwareTerms"
5953
]
6054
}

rustfmt.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
# format_macro_matchers (https://github.com/rust-lang/rustfmt/issues/3354)
88
# normalize_doc_attributes (https://github.com/rust-lang/rustfmt/issues/3351)
99
# overflow_delimited_expression (https://github.com/rust-lang/rustfmt/issues/3370)
10-
# where_single_line (https://github.com/rust-lang/rustfmt/issues/3359)
1110
# wrap_comments (https://github.com/rust-lang/rustfmt/issues/3347)
1211
unstable_features = true
1312

1413
max_width = 120
1514
comment_width = 120
15+
struct_lit_width = 25
1616
single_line_let_else_max_width = 120
17-
where_single_line = true
1817

1918
format_code_in_doc_comments = true
2019
format_macro_matchers = true

slice-codec/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[package]
22
name = "slice-codec"
3-
43
description = """
54
Library for encoding and decoding Slice types.
65
"""
76
homepage = "https://docs.icerpc.dev/slice2"
87
documentation = "https://docs.rs/slice-codec"
9-
repository = "https://github.com/icerpc/slice-rust"
8+
repository = "https://github.com/icerpc/slicec/slice-codec"
109
readme = "README.md"
1110
keywords = ["slice", "ice", "icerpc"]
1211
rust-version = "1.73"

slice-codec/src/buffer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait InputSource {
4242
/// This function reads exactly `dest.len()`-many bytes, or if it's unable to, returns an error instead.
4343
/// If such an error occurs, no guarantees are made about how many bytes were read from the source, except that it
4444
/// is less than `dest.len()`.
45-
fn read_bytes_into_exact(&mut self, dest: &mut [u8]) -> Result<()>;
45+
fn read_bytes_into_buffer(&mut self, dest: &mut [u8]) -> Result<()>;
4646
}
4747

4848
/// A trait for types that can be written to by a [Slice encoder](crate::encoder::Encoder).

slice-codec/src/buffer/slice.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl InputSource for SliceInputSource<'_> {
105105
Ok(byte_slice)
106106
}
107107

108-
fn read_bytes_into_exact(&mut self, dst: &mut [u8]) -> Result<()> {
108+
fn read_bytes_into_buffer(&mut self, dst: &mut [u8]) -> Result<()> {
109109
let src = self.read_byte_slice_exact(dst.len())?;
110110

111111
// SAFETY: `read_byte_slice_exact` is guaranteed to return exactly `dst.len()` bytes, so there is enough space
@@ -120,7 +120,8 @@ impl InputSource for SliceInputSource<'_> {
120120
}
121121

122122
impl<'a, T> From<&'a T> for SliceInputSource<'a>
123-
where T: Borrow<[u8]> + ?Sized
123+
where
124+
T: Borrow<[u8]> + ?Sized,
124125
{
125126
/// Creates a new [`SliceInputSource`] that wraps the provided buffer.
126127
fn from(value: &'a T) -> Self {
@@ -135,7 +136,8 @@ where T: Borrow<[u8]> + ?Sized
135136
// without needing to construct an intermediate [`SliceInputSource`].
136137
#[cfg(feature = "slice2")]
137138
impl<'a, T> From<T> for crate::decoder::Decoder<SliceInputSource<'a>>
138-
where T: Into<SliceInputSource<'a>>
139+
where
140+
T: Into<SliceInputSource<'a>>,
139141
{
140142
fn from(value: T) -> Self {
141143
crate::decoder::Decoder::new_with_inferred_encoding(value.into())
@@ -259,7 +261,8 @@ impl<'a, const N: usize> From<&'a mut [u8; N]> for SliceOutputTarget<'a> {
259261
// without needing to construct an intermediate [`SliceOutputTarget`].
260262
#[cfg(feature = "slice2")]
261263
impl<'a, T> From<T> for crate::encoder::Encoder<SliceOutputTarget<'a>>
262-
where T: Into<SliceOutputTarget<'a>>
264+
where
265+
T: Into<SliceOutputTarget<'a>>,
263266
{
264267
fn from(value: T) -> Self {
265268
crate::encoder::Encoder::new_with_inferred_encoding(value.into())

slice-codec/src/buffer/vec.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl OutputTarget for VecOutputTarget<'_> {
7474
let target_slice = self.buffer.spare_capacity_mut().get_unchecked_mut(..count);
7575

7676
debug_assert_eq!(target_slice.len(), count);
77-
// SAFETY: `MaybeUnit<T>` is guaranteed to have the same memory layout as `T`.
77+
// SAFETY: `MaybeUninit<T>` is guaranteed to have the same memory layout as `T`.
7878
let source: &[MaybeUninit<u8>] = core::mem::transmute(bytes);
7979

8080
core::ptr::copy_nonoverlapping(source.as_ptr(), target_slice.as_mut_ptr(), count);
@@ -145,7 +145,8 @@ impl<'a> From<&'a mut Vec<u8>> for VecOutputTarget<'a> {
145145
// without needing to construct an intermediate [`VecOutputTarget`].
146146
#[cfg(feature = "slice2")]
147147
impl<'a, T> From<T> for crate::encoder::Encoder<VecOutputTarget<'a>>
148-
where T: Into<VecOutputTarget<'a>>
148+
where
149+
T: Into<VecOutputTarget<'a>>,
149150
{
150151
fn from(value: T) -> Self {
151152
crate::encoder::Encoder::new_with_inferred_encoding(value.into())

slice-codec/src/error.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,15 @@ impl Display for ErrorKind {
137137
Self::UnexpectedEob { requested, remaining } => {
138138
write!(f, "unexpected end of buffer: attempted to read '{requested}' bytes from a buffer with only '{remaining}' bytes remaining")
139139
}
140-
Self::InvalidReservation { buffer_len, reserved_range } => {
140+
Self::InvalidReservation {
141+
buffer_len,
142+
reserved_range,
143+
} => {
141144
let Range { start, end } = reserved_range;
142-
write!(f, "invalid reservation: range '[{start}..{end})' does not fit within buffer of length '{buffer_len}'")
145+
write!(
146+
f,
147+
"invalid reservation: range '[{start}..{end})' does not fit within buffer of length '{buffer_len}'"
148+
)
143149
}
144150
Self::InvalidData(inner) => inner.fmt(f),
145151
_ => todo!(),
@@ -177,12 +183,7 @@ impl Display for InvalidDataErrorKind {
177183
write!(f, "illegal value: {desc}")
178184
}
179185
}
180-
Self::OutOfRange {
181-
value,
182-
min,
183-
max,
184-
typename,
185-
} => {
186+
Self::OutOfRange { value, min, max, typename } => {
186187
write!(
187188
f,
188189
"value '{value}' is outside the allowed range for type '{typename}'; values must be within [{min}..{max}]"

slice-codec/src/slice2/decoding.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ impl DecodeFrom<Slice2> for i8 {
6666

6767
implement_decode_from_on_numeric_primitive_type! {u16, Slice2, "Decodes a [`u16`] from 2 bytes (little endian)."}
6868
implement_decode_from_on_numeric_primitive_type! {i16, Slice2, "Decodes a [`i16`] from 2 bytes (little endian) in two's complement form."}
69-
implement_decode_from_on_numeric_primitive_type! {u32, Slice2, "Decodes a [`u32`] from 2 bytes (little endian)."}
69+
implement_decode_from_on_numeric_primitive_type! {u32, Slice2, "Decodes a [`u32`] from 4 bytes (little endian)."}
7070
implement_decode_from_on_numeric_primitive_type! {i32, Slice2, "Decodes a [`i32`] from 4 bytes (little endian) in two's complement form."}
71-
implement_decode_from_on_numeric_primitive_type! {u64, Slice2, "Decodes a [`u64`] from 2 bytes (little endian)."}
71+
implement_decode_from_on_numeric_primitive_type! {u64, Slice2, "Decodes a [`u64`] from 8 bytes (little endian)."}
7272
implement_decode_from_on_numeric_primitive_type! {i64, Slice2, "Decodes a [`i64`] from 8 bytes (little endian) in two's complement form."}
7373
implement_decode_from_on_numeric_primitive_type! {f32, Slice2, "Decodes a [`f32`] from 4 bytes (little endian) using the \"binary32\" representation defined in IEEE 754-2008."}
7474
implement_decode_from_on_numeric_primitive_type! {f64, Slice2, "Decodes a [`f64`] from 8 bytes (little endian) using the \"binary64\" representation defined in IEEE 754-2008."}
@@ -197,7 +197,8 @@ impl DecodeFrom<Slice2> for String {
197197

198198
#[cfg(feature = "alloc")]
199199
impl<T> DecodeFrom<Slice2> for Vec<T>
200-
where T: DecodeFrom<Slice2>
200+
where
201+
T: DecodeFrom<Slice2>,
201202
{
202203
/// TODO
203204
fn decode_from(decoder: &mut Decoder<impl InputSource, Slice2>) -> Result<Self> {

slice-codec/src/slice2/encoding.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ implement_encode_into_on_borrowed_type!(i8, Slice2);
4646

4747
implement_encode_into_on_numeric_primitive_type! {u16, Slice2, "Encodes this [`u16`] on 2 bytes (little endian)."}
4848
implement_encode_into_on_numeric_primitive_type! {i16, Slice2, "Encodes this [`i16`] on 2 bytes (little endian) in two's complement form."}
49-
implement_encode_into_on_numeric_primitive_type! {u32, Slice2, "Encodes this [`u32`] on 2 bytes (little endian)."}
49+
implement_encode_into_on_numeric_primitive_type! {u32, Slice2, "Encodes this [`u32`] on 4 bytes (little endian)."}
5050
implement_encode_into_on_numeric_primitive_type! {i32, Slice2, "Encodes this [`i32`] on 4 bytes (little endian) in two's complement form."}
51-
implement_encode_into_on_numeric_primitive_type! {u64, Slice2, "Encodes this [`u64`] on 2 bytes (little endian)."}
51+
implement_encode_into_on_numeric_primitive_type! {u64, Slice2, "Encodes this [`u64`] on 8 bytes (little endian)."}
5252
implement_encode_into_on_numeric_primitive_type! {i64, Slice2, "Encodes this [`i64`] on 8 bytes (little endian) in two's complement form."}
5353
implement_encode_into_on_numeric_primitive_type! {f32, Slice2, "Encodes this [`f32`] on 4 bytes (little endian) using the \"binary32\" representation defined in IEEE 754-2008."}
5454
implement_encode_into_on_numeric_primitive_type! {f64, Slice2, "Encodes this [`f64`] on 8 bytes (little endian) using the \"binary64\" representation defined in IEEE 754-2008."}
@@ -84,7 +84,6 @@ impl<O: OutputTarget> Encoder<O, Slice2> {
8484
///
8585
/// [varint]: https://docs.icerpc.dev/slice2/language-guide/primitive-types#variable-size-integral-types
8686
#[rustfmt::skip] // To keep the arms of `match required_bits` aligned for readability.
87-
8887
pub fn encode_varint(&mut self, value: impl Into<i64>) -> Result<()> {
8988
let value: i64 = value.into();
9089

@@ -154,7 +153,8 @@ impl EncodeInto<Slice2> for &str {
154153

155154
/// TODO
156155
impl<'a, T> EncodeInto<Slice2> for &'a [T]
157-
where &'a T: EncodeInto<Slice2>
156+
where
157+
&'a T: EncodeInto<Slice2>,
158158
{
159159
fn encode_into(self, encoder: &mut Encoder<impl OutputTarget, Slice2>) -> Result<()> {
160160
let size = u64::try_from(self.len())?;

0 commit comments

Comments
 (0)