into_inner_derive

Crates.iointo_inner_derive
lib.rsinto_inner_derive
version0.1.2
created_at2025-05-16 09:54:49.977965+00
updated_at2025-06-03 13:26:32.910467+00
descriptionDerive macro for IntoInner trait
homepage
repositoryhttps://gitlab.com/max.martinelli/into_inner
max_upload_size
id1676284
size12,171
Massimiliano Martinelli (max-1975)

documentation

https://docs.rs/into_inner_derive/latest/into_inner_derive/

README

into_inner_derive

Crates.io Docs.rs

Procedural macro for automatically implementing the IntoInner trait (from the into_inner crate) for tuple structs with a single field.


Overview

into_inner_derive provides the #[derive(IntoInner)] procedural macro, which generates an implementation of the IntoInner trait (from the into_inner crate) for tuple structs with exactly one field. This allows you to easily extract the inner value from wrapper types without writing boilerplate code.

Note:
You should not use this crate directly. Instead, use the macro re-exported by the main into_inner crate:

use into_inner::IntoInner;

#[derive(IntoInner)]
struct MyWrapper(String);

Usage

Add the main crate to your Cargo.toml:

[dependencies]
into_inner = "0.1"

Then, in your code:

use into_inner::IntoInner;

#[derive(IntoInner)]
struct MyWrapper(String);

let wrapper = MyWrapper("Hello, world!".to_string());
let inner = wrapper.into_inner();
assert_eq!(inner, "Hello, world!");

Limitations

  • The macro only works for tuple structs with exactly one field.
  • Using the macro on structs with named fields or multiple fields will result in a compile-time error.
  • The IntoInner trait must be in scope when using the macro.

Example: Compile-Time Error

use into_inner::IntoInner;

#[derive(IntoInner)]
struct InvalidWrapper(String, i32); // Error: only tuple structs with one field are supported

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Contribution

Contributions are welcome! Please open issues or pull requests on GitLab.


See Also

  • into_inner — the main crate re-exporting the trait and macro.
Commit count: 11

cargo fmt