13 releases

0.1.11 Nov 4, 2024
0.1.9 Sep 3, 2024
0.1.8 Jun 2, 2024
0.1.5 Mar 1, 2024
0.1.2 Oct 19, 2023

#420 in Data structures

Download history 566/week @ 2024-08-18 332/week @ 2024-08-25 419/week @ 2024-09-01 375/week @ 2024-09-08 448/week @ 2024-09-15 292/week @ 2024-09-22 372/week @ 2024-09-29 265/week @ 2024-10-06 283/week @ 2024-10-13 15/week @ 2024-10-20 7/week @ 2024-10-27 213/week @ 2024-11-03 12/week @ 2024-11-10 48/week @ 2024-11-17 18/week @ 2024-11-24 7/week @ 2024-12-01

92 downloads per month
Used in 2 crates (via lcax_convert)

MIT/Apache

31KB
326 lines

field_access

Build Status crates.io docs.rs License: Apache 2.0 License: MIT

A library for dynamic access to struct fields with #![no_std] support.

Field access is enabled by the FieldAccess trait which can be implemented using a derive macro by the same name.

use field_access::FieldAccess;

#[derive(FieldAccess)]
struct Foo {
    a: u8
}

let mut foo = Foo { a: 1 };

// Immutable field access.
if let Some(field) = foo.field("a") {
    assert_eq!(field.as_u8(), Some(1));
}

// Mutable field access.
if let Some(mut field) = foo.field_mut("a") {
    assert_eq!(field.replace(42u8), Some(1));
}

assert_eq!(foo.a, 42);

Cargo features

  • alloc: Provide methods to interact with types from the Rust core allocation and collections library including String and Vec<T>. This feature pulls in the alloc library as a dependency and is enabled by default.
  • derive: Provide a derive macro for the FieldAccess trait. This feature is enabled by default.

License

The source code of field_access is licensed under either of Apache License, Version 2.0 or MIT license at your option.

Dependencies

~105KB