Crates.io | into_inner_derive |
lib.rs | into_inner_derive |
version | 0.1.2 |
created_at | 2025-05-16 09:54:49.977965+00 |
updated_at | 2025-06-03 13:26:32.910467+00 |
description | Derive macro for IntoInner trait |
homepage | |
repository | https://gitlab.com/max.martinelli/into_inner |
max_upload_size | |
id | 1676284 |
size | 12,171 |
Procedural macro for automatically implementing the IntoInner
trait (from the into_inner
crate) for tuple structs with a single field.
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 maininto_inner
crate:use into_inner::IntoInner; #[derive(IntoInner)] struct MyWrapper(String);
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!");
IntoInner
trait must be in scope when using the macro.use into_inner::IntoInner;
#[derive(IntoInner)]
struct InvalidWrapper(String, i32); // Error: only tuple structs with one field are supported
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Contributions are welcome! Please open issues or pull requests on GitLab.