mirror of
https://gitee.com/openharmony/third_party_rust_memoffset
synced 2024-11-27 01:11:21 +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/
|
/target/
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
.idea/
|
||||||
|
cmake-build-debug/
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Gilad Naaman <gilad.naaman@gmail.com>"]
|
authors = ["Gilad Naaman <gilad.naaman@gmail.com>"]
|
||||||
description = "offset_of functionality for Rust structs."
|
description = "offset_of functionality for Rust structs."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -10,7 +10,3 @@ keywords = ["mem", "offset", "offset_of", "offsetof"]
|
|||||||
categories = ["no-std"]
|
categories = ["no-std"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["std"]
|
|
||||||
std = []
|
|
||||||
|
10
README.md
10
README.md
@ -8,18 +8,14 @@ Introduces the following macros:
|
|||||||
* `offset_of!` for obtaining the offset of a member of a struct.
|
* `offset_of!` for obtaining the offset of a member of a struct.
|
||||||
* `span_of!` for obtaining the range that a field, or fields, span.
|
* `span_of!` for obtaining the range that a field, or fields, span.
|
||||||
|
|
||||||
|
`memoffset` works under `no_std` environments.
|
||||||
|
|
||||||
## Usage ##
|
## Usage ##
|
||||||
Add the following dependency to your `Cargo.toml`:
|
Add the following dependency to your `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
memoffset = "0.1"
|
memoffset = "0.2"
|
||||||
```
|
|
||||||
|
|
||||||
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 }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Add the following lines at the top of your `main.rs` or `lib.rs` files.
|
Add the following lines at the top of your `main.rs` or `lib.rs` files.
|
||||||
|
10
src/lib.rs
10
src/lib.rs
@ -57,14 +57,10 @@
|
|||||||
//! let checksum = crc16(checksum_range);
|
//! let checksum = crc16(checksum_range);
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
// Support for the usage of this crate without the standard library.
|
#![no_std]
|
||||||
#![cfg_attr(not(feature="std"), no_std)]
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
// This `use` statement enables the macros to use `$crate::mem`.
|
||||||
#[doc(hidden)]
|
// Doing this enables this crate to function under both std and no-std crates.
|
||||||
pub use std::mem;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use core::mem;
|
pub use core::mem;
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ macro_rules! span_of {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::mem;
|
use ::core::mem;
|
||||||
|
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
|
Loading…
Reference in New Issue
Block a user