Skip to content

Commit

Permalink
Example to demonstrates the magic of blanket implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
radumarias committed Sep 23, 2024
1 parent cc2378d commit a8790cb
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 7 deletions.
61 changes: 59 additions & 2 deletions check-before-push.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,65 @@ set RUSTDOCFLAGS=-Dwarnings
cargo fmt --all
if %errorlevel% neq 0 exit /b %errorlevel%

cargo clippy --release --all-targets --fix --allow-dirty
cargo build --all-targets --all-features
if %errorlevel% neq 0 exit /b %errorlevel%

act --action-offline-mode -W .github/workflows/build_and_tests_reusable.yaml
cargo build --release --all-targets --all-features
if %errorlevel% neq 0 exit /b %errorlevel%

cargo clippy --release --all-targets --fix --allow-dirty --allow-staged
if %errorlevel% neq 0 exit /b %errorlevel%

cargo fmt --all -- --check
if %errorlevel% neq 0 exit /b %errorlevel%

cargo check --all
if %errorlevel% neq 0 exit /b %errorlevel%

cargo clippy --all-targets --release
if %errorlevel% neq 0 exit /b %errorlevel%

cargo test --release --all --all-features
if %errorlevel% neq 0 exit /b %errorlevel%

cargo doc --workspace --all-features --no-deps
if %errorlevel% neq 0 exit /b %errorlevel%

cargo publish --dry-run --allow-dirty
if %errorlevel% neq 0 exit /b %errorlevel%

cd java-bridge
cargo fmt --all
if %errorlevel% neq 0 exit /b %errorlevel%

cargo build --all-targets --all-features
if %errorlevel% neq 0 exit /b %errorlevel%

cargo build --release --all-targets --all-features
if %errorlevel% neq 0 exit /b %errorlevel%

cargo clippy --release --all-targets --fix --allow-dirty --allow-staged
if %errorlevel% neq 0 exit /b %errorlevel%

cargo fmt --all -- --check
if %errorlevel% neq 0 exit /b %errorlevel%

cargo check --all
if %errorlevel% neq 0 exit /b %errorlevel%

cargo clippy --all-targets --release ^
-A clippy::similar_names ^
-A clippy::too_many_arguments ^
-A clippy::significant_drop_tightening ^
-A clippy::redundant_closure ^
-A clippy::missing_errors_doc ^
-A clippy::type_complexity
if %errorlevel% neq 0 exit /b %errorlevel%

cargo test --release --all --all-features
if %errorlevel% neq 0 exit /b %errorlevel%

cargo doc --workspace --all-features --no-deps
if %errorlevel% neq 0 exit /b %errorlevel%

cd ..
38 changes: 36 additions & 2 deletions check-before-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,39 @@ export RUSTFLAGS="-Dwarnings"
export RUSTDOCFLAGS="-Dwarnings"

cargo fmt --all
cargo clippy --release --all-targets --fix --allow-dirty
act --action-offline-mode -W .github/workflows/build_and_tests_reusable.yaml

cargo build --all-targets --all-features --target x86_64-unknown-linux-gnu
cargo build --release --all-targets --all-features --target x86_64-unknown-linux-gnu
cargo clippy --release --all-targets --fix --allow-dirty --allow-staged --target x86_64-unknown-linux-gnu
cargo fmt --all -- --check
cargo check --all --target x86_64-unknown-linux-gnu
cargo clippy --all-targets --release --target x86_64-unknown-linux-gnu -- \
-A clippy::similar_names \
-A clippy::too_many_arguments \
-A clippy::significant_drop_tightening \
-A clippy::redundant_closure \
-A clippy::missing_errors_doc \
-A clippy::type_complexity
cargo test --release --all --all-features --target x86_64-unknown-linux-gnu
cargo doc --workspace --all-features --no-deps --target x86_64-unknown-linux-gnu
cargo publish --dry-run --allow-dirty --target x86_64-unknown-linux-gnu
cargo aur
cargo generate-rpm

cd java-bridge
cargo fmt --all
cargo build --all-targets --all-features --target x86_64-unknown-linux-gnu
cargo build --release --all-targets --all-features --target x86_64-unknown-linux-gnu
cargo clippy --release --all-targets --fix --allow-dirty --allow-staged --target x86_64-unknown-linux-gnu
cargo fmt --all -- --check
cargo check --all --target x86_64-unknown-linux-gnu
cargo clippy --all-targets --release --target x86_64-unknown-linux-gnu -- \
-A clippy::similar_names \
-A clippy::too_many_arguments \
-A clippy::significant_drop_tightening \
-A clippy::redundant_closure \
-A clippy::missing_errors_doc \
-A clippy::type_complexity
cargo test --release --all --all-features --target x86_64-unknown-linux-gnu
cargo doc --workspace --all-features --no-deps --target x86_64-unknown-linux-gnu
cd ..
6 changes: 3 additions & 3 deletions examples/magic_of_blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ fn main() {
// wrap only Read
let mut reader = MyRead { inner: OnlyRead {} };
println!("we can read");
reader.read(&mut [0; 10]).unwrap();
let _ = reader.read(&mut [0; 10]).unwrap();
// but we cannot seek
// reader.seek(SeekFrom::Start(0)).unwrap(); // compile error

// wrap Read + Seek
let mut reader_seek = MyRead { inner: ReadSeek {} };
println!("we can read");
reader_seek.read(&mut [0; 10]).unwrap();
let _ = reader_seek.read(&mut [0; 10]).unwrap();
println!("we can seek too");
reader_seek.seek(SeekFrom::Start(0)).unwrap();
}

struct OnlyRead {}
impl Read for OnlyRead {
fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
Ok(0)
}
}
Expand Down

0 comments on commit a8790cb

Please sign in to comment.