From 11631bfe8c9e9a4a5966949737ebabe5c3d3fb3e Mon Sep 17 00:00:00 2001 From: YdrMaster Date: Thu, 30 Jun 2022 13:14:43 +0800 Subject: [PATCH] feat: compile with stable rust Signed-off-by: YdrMaster --- CHANGELOG.md | 10 ++++++++++ Cargo.toml | 2 +- README.md | 3 ++- docs/README_EN.md | 3 ++- rust-toolchain.toml | 2 -- src/header.rs | 6 +++++- src/lib.rs | 1 - src/property/str.rs | 2 +- src/walker.rs | 2 +- 9 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 rust-toolchain.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 81b8782..6ccdd0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # 更新日志 Change Log +## v0.1.3 + +- 功能 + - 移除不稳定特性,支持 stable 编译 + +--- + +- feature + - removes unstable features and allows to compile with stable rust + ## v0.1.2 - 功能 diff --git a/Cargo.toml b/Cargo.toml index 8a91c50..0a1c7c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dtb-walker" description = "A simple package for DTB depth-first walking." -version = "0.1.2" +version = "0.1.3" edition = "2021" authors = ["YdrMaster "] repository = "https://github.com/YdrMaster/dtb-walker.git" diff --git a/README.md b/README.md index 17adbb0..d0db141 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,10 @@ cargo run --release --example qemu-virt 特性: -- [x] 可选是否检查首部正确性; +- [x] stable rust - [x] `no_std`; - [x] 不需要 `alloc`; +- [x] 可选是否检查首部正确性; - [x] 提前终止遍历; - [x] 低开销跳过节点; - [ ] 内置标准属性解析; diff --git a/docs/README_EN.md b/docs/README_EN.md index c56a831..a315dcf 100644 --- a/docs/README_EN.md +++ b/docs/README_EN.md @@ -15,9 +15,10 @@ Following the [devicetree-specification-v0.4-rc1](https://github.com/devicetree- Features: -- [x] optional header verifying; +- [x] stable rust - [x] `no_std`; - [x] without `alloc`; +- [x] optional header verifying; - [x] terminate walking at any time; - [x] step over nodes with low overhead; - [ ] built-in standard property parsing; diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 5d56faf..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "nightly" diff --git a/src/header.rs b/src/header.rs index 3fb9324..596e023 100644 --- a/src/header.rs +++ b/src/header.rs @@ -157,5 +157,9 @@ fn misaligned(addr: u32) -> u32 { #[inline] fn check(filter: impl Fn(&HeaderError) -> bool, err: HeaderError) -> Result<(), HeaderError> { - filter(&err).then_some(()).ok_or(err) + if filter(&err) { + Ok(()) + } else { + Err(err) + } } diff --git a/src/lib.rs b/src/lib.rs index 20de1a7..1c9d8b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![feature(slice_internals)] #![deny(warnings)] // cancel this line during developing mod header; diff --git a/src/property/str.rs b/src/property/str.rs index 20c2514..24f0413 100644 --- a/src/property/str.rs +++ b/src/property/str.rs @@ -71,7 +71,7 @@ impl<'a> Iterator for StrList<'a> { } let (head, tail) = self .0 - .split_at(slice::memchr::memchr(b'\0', self.0).unwrap()); + .split_at(self.0.iter().position(|c| *c == b'\0').unwrap()); self.0 = &tail[1..]; Some(Str(head)) } diff --git a/src/walker.rs b/src/walker.rs index e34ed2c..b631f9c 100644 --- a/src/walker.rs +++ b/src/walker.rs @@ -12,7 +12,7 @@ impl Walker<'_> { fn prop_name(&self, nameoff: Blk) -> &[u8] { let nameoff = nameoff.into_u32() as usize; let name = &self.strings[nameoff..]; - &name[..slice::memchr::memchr(b'\0', name).unwrap()] + &name[..name.iter().position(|c| *c == b'\0').unwrap()] } /// 深度优先遍历。如果返回 `false`,取消所有后续的遍历。