Skip to content
This repository was archived by the owner on Mar 20, 2022. It is now read-only.

Commit 6ea8582

Browse files
committed
Fixed BufferSize::try_from returning incorrect values for 4, 8, and 16 KB.
1 parent 8237a1b commit 6ea8582

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
on:
22
push:
3+
branches:
4+
- main
5+
tags:
6+
- 'v*'
37
pull_request:
48
schedule:
59
- cron: "13 3 * * *"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
tarpaulin-report.html

CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [0.8.0] - 2021-05-08
88
### Added
99
- Added `Display` for `SocketInterruptMask`.
1010
- Added `Display` for `SocketMode`.
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Changed
1414
- Changed the display formatting for `LinkStatus` and `SocketInterrupt`.
1515

16+
### Fixed
17+
- Fixed `BufferSize::try_from` returning incorrect values for 4, 8, and 16 KB.
18+
1619
## [0.7.0] - 2021-02-23
1720
### Changed
1821
- Updated `defmt` dependency from 0.1.3 to 0.2.0.
@@ -107,7 +110,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
107110
## [0.1.0] - 2021-01-02
108111
- Initial release
109112

110-
[Unreleased]: https://github.com/newAM/w5500-ll-rs/compare/v0.7.0...HEAD
113+
[Unreleased]: https://github.com/newAM/w5500-ll-rs/compare/v0.8.0...HEAD
114+
[0.8.0]: https://github.com/newAM/w5500-ll-rs/compare/v0.7.0...v0.8.0
111115
[0.7.0]: https://github.com/newAM/w5500-ll-rs/compare/v0.6.2...v0.7.0
112116
[0.6.2]: https://github.com/newAM/w5500-ll-rs/compare/v0.6.1...v0.6.2
113117
[0.6.1]: https://github.com/newAM/w5500-ll-rs/compare/v0.6.0...v0.6.1

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "w5500-ll"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["Alex M. <[email protected]>"]
55
edition = "2018"
66
repository = "https://github.com/newAM/w5500-ll-rs"
@@ -22,12 +22,12 @@ version = "~0.2.4"
2222
optional = true
2323

2424
[dependencies.defmt]
25-
version = "~0.2.0"
25+
version = "~0.2"
2626
optional = true
2727

2828
[dev-dependencies]
2929
embedded-hal-mock = "~0.7"
30-
version-sync = "~0.9.1"
30+
version-sync = "~0.9"
3131

3232
[package.metadata.docs.rs]
3333
all-features = true

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
//! [w5500-hl]: https://github.com/newAM/w5500-hl-rs
5151
//! [w5500-regsim]: https://github.com/newAM/w5500-regsim-rs
5252
//! [Wiznet W5500]: https://www.wiznet.io/product-item/w5500/
53-
//! [`blocking`]: https://docs.rs/w5500-ll/0.7.0/w5500_ll/blocking/index.html
54-
//! [`Registers`]: https://docs.rs/w5500-ll/0.7.0/w5500_ll/trait.Registers.html
55-
//! [`w5500_ll::net`]: https://docs.rs/w5500-ll/0.7.0/w5500_ll/net/index.html
56-
#![doc(html_root_url = "https://docs.rs/w5500-ll/0.7.0")]
53+
//! [`blocking`]: https://docs.rs/w5500-ll/0.8.0/w5500_ll/blocking/index.html
54+
//! [`Registers`]: https://docs.rs/w5500-ll/0.8.0/w5500_ll/trait.Registers.html
55+
//! [`w5500_ll::net`]: https://docs.rs/w5500-ll/0.8.0/w5500_ll/net/index.html
56+
#![doc(html_root_url = "https://docs.rs/w5500-ll/0.8.0")]
5757
#![cfg_attr(docsrs, feature(doc_cfg))]
5858
#![forbid(unsafe_code)]
5959
#![forbid(missing_docs)]

src/specifiers.rs

+44-3
Original file line numberDiff line numberDiff line change
@@ -559,26 +559,67 @@ pub enum BufferSize {
559559
KB16 = 16,
560560
}
561561
impl From<BufferSize> for u8 {
562+
/// Get the register value from a buffer size.
563+
///
564+
/// # Example
565+
///
566+
/// ```
567+
/// use w5500_ll::BufferSize;
568+
///
569+
/// assert_eq!(u8::from(BufferSize::KB0), 0);
570+
/// assert_eq!(u8::from(BufferSize::KB1), 1);
571+
/// assert_eq!(u8::from(BufferSize::KB2), 2);
572+
/// assert_eq!(u8::from(BufferSize::KB4), 4);
573+
/// assert_eq!(u8::from(BufferSize::KB8), 8);
574+
/// assert_eq!(u8::from(BufferSize::KB16), 16);
575+
/// ```
562576
fn from(val: BufferSize) -> u8 {
563577
val as u8
564578
}
565579
}
580+
566581
impl TryFrom<u8> for BufferSize {
567582
type Error = u8;
583+
584+
/// Get the buffer size given the register value.
585+
///
586+
/// # Example
587+
///
588+
/// ```
589+
/// use core::convert::TryFrom;
590+
/// use w5500_ll::BufferSize;
591+
///
592+
/// assert_eq!(BufferSize::try_from(0), Ok(BufferSize::KB0));
593+
/// assert_eq!(BufferSize::try_from(1), Ok(BufferSize::KB1));
594+
/// assert_eq!(BufferSize::try_from(2), Ok(BufferSize::KB2));
595+
/// assert_eq!(BufferSize::try_from(4), Ok(BufferSize::KB4));
596+
/// assert_eq!(BufferSize::try_from(8), Ok(BufferSize::KB8));
597+
/// assert_eq!(BufferSize::try_from(16), Ok(BufferSize::KB16));
598+
/// assert_eq!(BufferSize::try_from(17), Err(17));
599+
/// ```
568600
fn try_from(val: u8) -> Result<BufferSize, u8> {
569601
match val {
570602
x if x == BufferSize::KB0 as u8 => Ok(BufferSize::KB0),
571603
x if x == BufferSize::KB1 as u8 => Ok(BufferSize::KB1),
572604
x if x == BufferSize::KB2 as u8 => Ok(BufferSize::KB2),
573-
x if x == BufferSize::KB4 as u8 => Ok(BufferSize::KB0),
574-
x if x == BufferSize::KB8 as u8 => Ok(BufferSize::KB0),
575-
x if x == BufferSize::KB16 as u8 => Ok(BufferSize::KB0),
605+
x if x == BufferSize::KB4 as u8 => Ok(BufferSize::KB4),
606+
x if x == BufferSize::KB8 as u8 => Ok(BufferSize::KB8),
607+
x if x == BufferSize::KB16 as u8 => Ok(BufferSize::KB16),
576608
_ => Err(val),
577609
}
578610
}
579611
}
580612

581613
impl Default for BufferSize {
614+
/// Default buffer size.
615+
///
616+
/// # Example
617+
///
618+
/// ```
619+
/// use w5500_ll::BufferSize;
620+
///
621+
/// assert_eq!(BufferSize::default(), BufferSize::KB2);
622+
/// ```
582623
fn default() -> Self {
583624
BufferSize::KB2
584625
}

0 commit comments

Comments
 (0)