mirror of
https://gitee.com/openharmony/third_party_rust_memoffset
synced 2024-11-22 22:59:51 +00:00
Bumped version to 0.2
This commit is contained in:
parent
03cc3186d2
commit
a9cc05526c
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
/target/
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
.idea/
|
||||
cmake-build-debug/
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "memoffset"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
authors = ["Gilad Naaman <gilad.naaman@gmail.com>"]
|
||||
description = "offset_of functionality for Rust structs."
|
||||
license = "MIT"
|
||||
@ -10,7 +10,3 @@ keywords = ["mem", "offset", "offset_of", "offsetof"]
|
||||
categories = ["no-std"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = []
|
||||
|
12
README.md
12
README.md
@ -8,18 +8,14 @@ Introduces the following macros:
|
||||
* `offset_of!` for obtaining the offset of a member of a struct.
|
||||
* `span_of!` for obtaining the range that a field, or fields, span.
|
||||
|
||||
`memoffset` works under `no_std` environments.
|
||||
|
||||
## Usage ##
|
||||
Add the following dependency to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
memoffset = "0.1"
|
||||
```
|
||||
|
||||
If you're working in a no-std environment, use the following dependency instead (functionality is identical):
|
||||
```toml
|
||||
[dependencies]
|
||||
memoffset = { version = "0.1", default-features = false }
|
||||
memoffset = "0.2"
|
||||
```
|
||||
|
||||
Add the following lines at the top of your `main.rs` or `lib.rs` files.
|
||||
@ -48,4 +44,4 @@ assert_eq!(span_of!(Foo, a .. c[1]), 0..9);
|
||||
assert_eq!(span_of!(Foo, a ..= c[1]), 0..10);
|
||||
assert_eq!(span_of!(Foo, ..= d), 0..14);
|
||||
assert_eq!(span_of!(Foo, b ..), 4..17);
|
||||
```
|
||||
```
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -57,14 +57,10 @@
|
||||
//! let checksum = crc16(checksum_range);
|
||||
//! ```
|
||||
|
||||
// Support for the usage of this crate without the standard library.
|
||||
#![cfg_attr(not(feature="std"), no_std)]
|
||||
#![no_std]
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[doc(hidden)]
|
||||
pub use std::mem;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
// This `use` statement enables the macros to use `$crate::mem`.
|
||||
// Doing this enables this crate to function under both std and no-std crates.
|
||||
#[doc(hidden)]
|
||||
pub use core::mem;
|
||||
|
||||
|
@ -132,7 +132,7 @@ macro_rules! span_of {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::mem;
|
||||
use ::core::mem;
|
||||
|
||||
#[repr(C, packed)]
|
||||
struct Foo {
|
||||
|
Loading…
Reference in New Issue
Block a user