{"id":13672375,"url":"https://github.com/JelteF/derive_more","last_synced_at":"2025-04-27T21:32:52.084Z","repository":{"id":38325442,"uuid":"54630945","full_name":"JelteF/derive_more","owner":"JelteF","description":"Some more derive(Trait) options","archived":false,"fork":false,"pushed_at":"2025-04-18T11:52:43.000Z","size":8132,"stargazers_count":1876,"open_issues_count":71,"forks_count":130,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-22T17:06:53.909Z","etag":null,"topics":["derive","developer-tools","macros","newtype","rust","trait"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JelteF.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-03-24T09:38:18.000Z","updated_at":"2025-04-21T19:55:11.000Z","dependencies_parsed_at":"2024-03-15T11:44:42.298Z","dependency_job_id":"eb2eb505-c65a-43b6-818c-1ceab10d018a","html_url":"https://github.com/JelteF/derive_more","commit_stats":{"total_commits":724,"total_committers":64,"mean_commits":11.3125,"dds":0.2099447513812155,"last_synced_commit":"604dba87fef71dfc4563f18ee963d9c2c73c30e3"},"previous_names":["jeltef/derive_from"],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelteF%2Fderive_more","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelteF%2Fderive_more/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelteF%2Fderive_more/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelteF%2Fderive_more/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JelteF","download_url":"https://codeload.github.com/JelteF/derive_more/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251212775,"owners_count":21553518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["derive","developer-tools","macros","newtype","rust","trait"],"created_at":"2024-08-02T09:01:33.733Z","updated_at":"2025-04-27T21:32:52.077Z","avatar_url":"https://github.com/JelteF.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# `derive_more`\n\n[![Build Status](https://github.com/JelteF/derive_more/actions/workflows/ci.yml/badge.svg)](https://github.com/JelteF/derive_more/actions)\n[![Latest Version](https://img.shields.io/crates/v/derive_more.svg)](https://crates.io/crates/derive_more)\n[![Rust Documentation](https://docs.rs/derive_more/badge.svg)](https://docs.rs/derive_more)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/JelteF/derive_more/master/LICENSE)\n[![Rust 1.75+](https://img.shields.io/badge/rustc-1.75+-lightgray.svg)](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html)\n[![Unsafe Forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance)\n\nRust has lots of builtin traits that are implemented for its basic types, such\nas `Add`, `Not`, `From` or `Display`.\nHowever, when wrapping these types inside your own structs or enums you lose the\nimplementations of these traits and are required to recreate them.\nThis is especially annoying when your own structures are very simple, such as\nwhen using the commonly advised newtype pattern (e.g. `MyInt(i32)`).\n\nThis library tries to remove these annoyances and the corresponding boilerplate code.\nIt does this by allowing you to derive lots of commonly used traits for both structs and enums.\n\n\n\n\n## Example code\n\nBy using this library the following code just works:\n\n```rust\nuse derive_more::{Add, Display, From, Into};\n\n#[derive(PartialEq, From, Add)]\nstruct MyInt(i32);\n\n#[derive(PartialEq, From, Into)]\nstruct Point2D {\n    x: i32,\n    y: i32,\n}\n\n#[derive(PartialEq, From, Add, Display)]\nenum MyEnum {\n    #[display(\"int: {_0}\")]\n    Int(i32),\n    Uint(u32),\n    #[display(\"nothing\")]\n    Nothing,\n}\n\nassert!(MyInt(11) == MyInt(5) + 6.into());\nassert!((5, 6) == Point2D { x: 5, y: 6 }.into());\nassert!(MyEnum::Int(15) == (MyEnum::Int(8) + 7.into()).unwrap());\nassert!(MyEnum::Int(15).to_string() == \"int: 15\");\nassert!(MyEnum::Uint(42).to_string() == \"42\");\nassert!(MyEnum::Nothing.to_string() == \"nothing\");\n```\n\n\n\n\n## The derivable traits\n\nBelow are all the traits that you can derive using this library.\nSome trait derivations are so similar that the further documentation will only show a single one\nof them.\nYou can recognize these by the \"-like\" suffix in their name.\nThe trait name before that will be the only one that is used throughout the further\ndocumentation.\n\nIt is important to understand what code gets generated when using one of the\nderives from this crate.\nThat is why the links below explain what code gets generated for a trait for\neach group from before.\n\nYou can use the [`cargo-expand`] utility to see the exact code that is generated\nfor your specific type.\nThis will show you your code with all macros and derives expanded.\n\n**NOTE**: You still have to derive each trait separately. So `#[derive(Mul)]` doesn't\nautomatically derive `Div` as well. To derive both you should do `#[derive(Mul, Div)]`\n\n\n### Conversion traits\n\nThese are traits that are used to convert automatically between types.\n\n1. [`From`]\n2. [`Into`]\n3. [`FromStr`]\n4. [`TryFrom`]\n5. [`TryInto`]\n6. [`IntoIterator`]\n7. [`AsRef`], [`AsMut`]\n\n\n### Formatting traits\n\nThese traits are used for converting a struct to a string in different ways.\n\n1. [`Debug`]\n2. [`Display`-like], contains `Display`, `Binary`, `Octal`, `LowerHex`,\n   `UpperHex`, `LowerExp`, `UpperExp`, `Pointer`\n\n\n### Error-handling traits\n\nThese traits are used to define error-types.\n\n1. [`Error`]\n\n\n### Operators\n\nThese are traits that can be used for operator overloading.\n\n1. [`Index`]\n2. [`Deref`]\n3. [`Not`-like], contains `Not` and `Neg`\n4. [`Add`-like], contains `Add`, `Sub`, `BitAnd`, `BitOr`, `BitXor`\n5. [`Mul`-like], contains `Mul`, `Div`, `Rem`, `Shr` and `Shl`\n6. [`Sum`-like], contains `Sum` and `Product`\n7. [`IndexMut`]\n8. [`DerefMut`]\n9. [`AddAssign`-like], contains `AddAssign`, `SubAssign`, `BitAndAssign`,\n   `BitOrAssign` and `BitXorAssign`\n10. [`MulAssign`-like], contains `MulAssign`, `DivAssign`, `RemAssign`,\n    `ShrAssign` and `ShlAssign`\n\n\n### Static methods\n\nThese don't derive traits, but derive static methods instead.\n\n1. [`Constructor`], this derives a `new` method that can be used as a constructor.\n   This is very basic if you need more customization for your constructor, check\n   out the [`derive-new`] crate.\n2. [`IsVariant`], for each variant `foo` of an enum type, derives a `is_foo` method.\n3. [`Unwrap`], for each variant `foo` of an enum type, derives an `unwrap_foo` method.\n4. [`TryUnwrap`], for each variant `foo` of an enum type, derives an `try_unwrap_foo` method.\n\n\n### Re-exports\n\nThis crate also re-exports all the standard library traits, that it adds derives\nfor, in the `with_trait` module. So, both the `Display` derive and the `Display`\ntrait will be in scope when you add the following code:\n```rust\nuse derive_more::with_trait::Display; // also imports `core::fmt::Display`\n```\n\nBy default, derive macros only, without the corresponding traits, are imported from\nthe crate's root (or from the `derive` module):\n```rust\nuse derive_more::Display;   // imports macro only\nuse derive_more::derive::*; // imports all macros only\n```\n\n#### Hygiene\n\nFor hygiene purposes, macros use `derive_more::*` absolute paths in their expansions.\nThis might introduce a trouble, if you want to re-export `derive_more` macros in your\nown crate without using the `derive_more` as a direct dependency in downstream crates:\n```rust,ignore\nuse my_lib::Display; // re-exported in `my_lib` crate\n\n#[derive(Display)] // error: could not find `derive_more` in the list of imported crates\nstruct MyInt(i32);\n```\nIn such case, you should re-export the `derive_more` module too:\n```rust,ignore\nuse my_lib::{derive_more, Display}; // re-exported in `my_lib` crate\n\n#[derive(Display)] // works fine now!\nstruct MyInt(i32);\n```\n\n\n\n\n## Installation\n\nTo avoid redundant compilation times, by default no derives are supported.\nYou have to enable each type of derive as a feature in `Cargo.toml`:\n```toml\n[dependencies]\n# You can specify the types of derives that you need for less time spent\n# compiling. For the full list of features see this crate its `Cargo.toml`.\nderive_more = { version = \"2\", features = [\"from\", \"add\", \"into_iterator\"] }\n```\n```toml\n[dependencies]\n# If you don't care much about compilation times and simply want to have\n# support for all the possible derives, you can use the \"full\" feature.\nderive_more = { version = \"2\", features = [\"full\"] }\n```\n```toml\n[dependencies]\n# If you run in a `no_std` environment you should disable the default features,\n# because the only default feature is the \"std\" feature.\n# NOTE: You can combine this with \"full\" feature to get support for all the\n#       possible derives in a `no_std` environment.\nderive_more = { version = \"2\", default-features = false }\n```\n\nAnd this to the top of your Rust file:\n```rust\n// use the derives that you want in the file\nuse derive_more::{Add, Display, From};\n```\nIf you're still using Rust 2015, add this instead:\n```rust,edition2015\nextern crate core;\n#[macro_use]\nextern crate derive_more;\n# fn main() {} // omit wrapping statements above into `main()` in tests\n```\n\n\n## [MSRV] policy\n\nThis library requires Rust 1.75 or higher.\n\nChanging [MSRV] (minimum supported Rust version) of this crate is treated as a **minor version change** in terms of [Semantic Versioning].\n- So, if [MSRV] changes are **NOT concerning** for your project, just use the default [caret requirement]:\n  ```toml\n  [dependencies]\n  derive_more = \"2\" # or \"2.0\", or \"^2.0\"\n  ```\n- However, if [MSRV] changes are concerning for your project, then use the [tilde requirement] to **pin to a specific minor version**:\n  ```toml\n  [dependencies]\n  derive_more = \"~2.0\" # or \"~2.0.0\"\n  ```\n\n\n\n\n[`cargo-expand`]: https://github.com/dtolnay/cargo-expand\n[`derive-new`]: https://github.com/nrc/derive-new\n\n[`From`]: https://docs.rs/derive_more/latest/derive_more/derive.From.html\n[`Into`]: https://docs.rs/derive_more/latest/derive_more/derive.Into.html\n[`FromStr`]: https://docs.rs/derive_more/latest/derive_more/derive.FromStr.html\n[`TryFrom`]: https://docs.rs/derive_more/latest/derive_more/derive.TryFrom.html\n[`TryInto`]: https://docs.rs/derive_more/latest/derive_more/derive.TryInto.html\n[`IntoIterator`]: https://docs.rs/derive_more/latest/derive_more/derive.IntoIterator.html\n[`AsRef`]: https://docs.rs/derive_more/latest/derive_more/derive.AsRef.html\n[`AsMut`]: https://docs.rs/derive_more/latest/derive_more/derive.AsMut.html\n\n[`Debug`]: https://docs.rs/derive_more/latest/derive_more/derive.Debug.html\n[`Display`-like]: https://docs.rs/derive_more/latest/derive_more/derive.Display.html\n\n[`Error`]: https://docs.rs/derive_more/latest/derive_more/derive.Error.html\n\n[`Index`]: https://docs.rs/derive_more/latest/derive_more/derive.Index.html\n[`Deref`]: https://docs.rs/derive_more/latest/derive_more/derive.Deref.html\n[`Not`-like]: https://docs.rs/derive_more/latest/derive_more/derive.Not.html\n[`Add`-like]: https://docs.rs/derive_more/latest/derive_more/derive.Add.html\n[`Mul`-like]: https://docs.rs/derive_more/latest/derive_more/derive.Mul.html\n[`Sum`-like]: https://docs.rs/derive_more/latest/derive_more/derive.Sum.html\n[`IndexMut`]: https://docs.rs/derive_more/latest/derive_more/derive.IndexMut.html\n[`DerefMut`]: https://docs.rs/derive_more/latest/derive_more/derive.DerefMut.html\n[`AddAssign`-like]: https://docs.rs/derive_more/latest/derive_more/derive.AddAssign.html\n[`MulAssign`-like]: https://docs.rs/derive_more/latest/derive_more/derive.MulAssign.html\n\n[`Constructor`]: https://docs.rs/derive_more/latest/derive_more/derive.Constructor.html\n[`IsVariant`]: https://docs.rs/derive_more/latest/derive_more/derive.IsVariant.html\n[`Unwrap`]: https://docs.rs/derive_more/latest/derive_more/derive.Unwrap.html\n[`TryUnwrap`]: https://docs.rs/derive_more/latest/derive_more/derive.TryUnwrap.html\n\n[caret requirement]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#caret-requirements\n[tilde requirement]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#tilde-requirements\n[MSRV]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field\n[Semantic Versioning]: http://semver.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJelteF%2Fderive_more","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJelteF%2Fderive_more","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJelteF%2Fderive_more/lists"}