<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="Educe"><title>educe - Rust</title><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-5bc39a1768837dd0.css"><metaname="rustdoc-vars"data-root-path="../"data-static-root-path="../static.files/"data-current-crate="educe"data-themes=""data-resource-suffix=""data-rustdoc-version="1.77.2 (25ef9e3d8 2024-04-09)"data-channel="1.77.2"data-search-js="search-dd67cee4cfa65049.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../static.files/storage-4c98445ec4002617.js"></script><scriptdefersrc="../crates.js"></script><scriptdefersrc="../static.files/main-48f368f3872407c8.js"></script><noscript><linkrel="stylesheet"href="../static.files/noscript-04d5337699b92874.css"></noscript><linkrel="alternate icon"type="image/png"href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><linkrel="alternate icon"type="image/png"href="../static.files/favicon-32x32-422f7d1d52889060.png"><linkrel="icon"type="image/svg+xml"href="../static.files/favicon-2c020d218678b618.svg"></head><bodyclass="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle"title="show sidebar"></button></nav><navclass="sidebar"><divclass="sidebar-crate"><h2><ahref="../educe/index.html">educe</a><spanclass="version">0.5.11</span></h2></div><divclass="sidebar-elems"><ulclass="block">
<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../educe/all.html"title="show sidebar"></a></div><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"tabindex="-1"><ahref="../help.html"title="help">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Crate <aclass="mod"href="#">educe</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../src/educe/lib.rs.html#1-2019">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><h2id="educe"><aclass="doc-anchor"href="#educe">§</a>Educe</h2>
<p>By default, every trait this crate supports will be enabled. You can disable all of them by turning off the default features and enable only the traits that you want to use by adding them to the <code>features</code> explicitly.</p>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(Debug)]</code> to implement the <code>Debug</code> trait for a struct, enum, or union. This allows you to modify the names of your types, variants, and fields. You can also choose to ignore specific fields or set a method to replace the <code>Debug</code> trait. Additionally, you have the option to format a struct as a tuple and vice versa.</p>
<h6id="change-the-name-of-a-type-a-variant-or-a-field"><aclass="doc-anchor"href="#change-the-name-of-a-type-a-variant-or-a-field">§</a>Change the Name of a Type, a Variant or a Field</h6>
<p>The <code>name</code> parameter can rename a type, a variant or a field. If you set it to <code>false</code>, the name can be ignored or forced to show otherwise.</p>
<h6id="use-another-method-to-handle-the-formatting"><aclass="doc-anchor"href="#use-another-method-to-handle-the-formatting">§</a>Use Another Method to Handle the Formatting</h6>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>Debug</code> trait for a field, eliminating the need to implement the <code>Debug</code> trait for the type of that field.</p>
<h6id="generic-parameters-bound-to-the-debug-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-debug-trait-or-others">§</a>Generic Parameters Bound to the <code>Debug</code> Trait or Others</h6>
<p>A union will be formatted as a <code>u8</code> slice because we don’t know its fields at runtime. The fields of a union cannot be ignored, renamed, or formatted with other methods. The implementation is <strong>unsafe</strong> because it may expose uninitialized memory.</p>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(Clone)]</code> to implement the <code>Clone</code> trait for a struct, an enum, or a union. You can set a method to replace the <code>Clone</code> trait.</p>
<h6id="use-another-method-to-perform-cloning"><aclass="doc-anchor"href="#use-another-method-to-perform-cloning">§</a>Use Another Method to Perform Cloning</h6>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>Clone</code> trait for a field, eliminating the need to implement the <code>Clone</code> trait for the type of that field.</p>
<h6id="generic-parameters-bound-to-the-clone-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-clone-trait-or-others">§</a>Generic Parameters Bound to the <code>Clone</code> Trait or Others</h6>
<p>Generic parameters will be automatically bound to the <code>Clone</code> trait if necessary. If the <code>#[educe(Copy)]</code> attribute exists, they will be bound to the <code>Copy</code> trait.</p>
<h6id="generic-parameters-bound-to-the-copy-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-copy-trait-or-others">§</a>Generic Parameters Bound to the <code>Copy</code> Trait or Others</h6>
<p>Note that utilizing custom cloning methods for a type that implements the <code>Copy</code> and <code>Clone</code> traits may not be entirely appropriate.</p>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(PartialEq)]</code> to implement the <code>PartialEq</code> trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the <code>PartialEq</code> trait.</p>
<h6id="use-another-method-to-perform-comparison"><aclass="doc-anchor"href="#use-another-method-to-perform-comparison">§</a>Use Another Method to Perform Comparison</h6>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>PartialEq</code> trait for a field, eliminating the need to implement the <code>PartialEq</code> trait for the type of that field.</p>
<h6id="generic-parameters-bound-to-the-partialeq-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-partialeq-trait-or-others">§</a>Generic Parameters Bound to the <code>PartialEq</code> Trait or Others</h6>
<p>The <code>#[educe(PartialEq(unsafe))]</code> attribute can be used for a union. The fields of a union cannot be compared with other methods. The implementation is <strong>unsafe</strong> because it disregards the specific fields it utilizes.</p>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(Eq)]</code> to implement the <code>Eq</code> trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the <code>PartialEq</code> trait.</p>
<h6id="use-another-method-to-perform-comparison-1"><aclass="doc-anchor"href="#use-another-method-to-perform-comparison-1">§</a>Use Another Method to Perform Comparison</h6>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>Eq</code> trait for a field, eliminating the need to implement the <code>PartialEq</code> trait for the type of that field.</p>
<h6id="generic-parameters-bound-to-the-partialeq-trait-or-others-1"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-partialeq-trait-or-others-1">§</a>Generic Parameters Bound to the <code>PartialEq</code> Trait or Others</h6>
<p>The <code>#[educe(PartialEq(unsafe), Eq)]</code> attribute can be used for a union. The fields of a union cannot be compared with other methods. The implementation is <strong>unsafe</strong> because it disregards the specific fields it utilizes.</p>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(PartialOrd)]</code> to implement the <code>PartialOrd</code> trait for a struct or enum. You can also choose to ignore specific fields or set a method to replace the <code>PartialOrd</code> trait.</p>
<h6id="use-another-method-to-perform-comparison-2"><aclass="doc-anchor"href="#use-another-method-to-perform-comparison-2">§</a>Use Another Method to Perform Comparison</h6>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>PartialOrd</code> trait for a field, eliminating the need to implement the <code>PartialOrd</code> trait for the type of that field.</p>
<p>Each field can add a <code>#[educe(PartialOrd(rank = priority_value))]</code> attribute, where <code>priority_value</code> is an integer value indicating its comparison precedence (lower values indicate higher priority). The default <code>priority_value</code> for a field depends on its ordinal position (lower towards the front) and starts with <code>isize::MIN</code>.</p>
<p>For variants, the discriminant can be explicitly set for comparison.</p>
<divclass="example-wrap ignore"><ahref="#"class="tooltip"title="This example is not tested">ⓘ</a><preclass="rust rust-example-rendered"><code><spanclass="kw">use </span>educe::Educe;
<h6id="generic-parameters-bound-to-the-partialord-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-partialord-trait-or-others">§</a>Generic Parameters Bound to the <code>PartialOrd</code> Trait or Others</h6>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(Ord)]</code> to implement the <code>Ord</code> trait for a struct or enum. You can also choose to ignore specific fields or set a method to replace the <code>Ord</code> trait.</p>
<h6id="use-another-method-to-perform-comparison-3"><aclass="doc-anchor"href="#use-another-method-to-perform-comparison-3">§</a>Use Another Method to Perform Comparison</h6>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>Ord</code> trait for a field, eliminating the need to implement the <code>Ord</code> trait for the type of that field.</p>
<p>Each field can add a <code>#[educe(Ord(rank = priority_value))]</code> attribute, where <code>priority_value</code> is an integer value indicating its comparison precedence (lower values indicate higher priority). The default <code>priority_value</code> for a field depends on its ordinal position (lower towards the front) and starts with <code>isize::MIN</code>.</p>
<p>For variants, the discriminant can be explicitly set for comparison.</p>
<divclass="example-wrap ignore"><ahref="#"class="tooltip"title="This example is not tested">ⓘ</a><preclass="rust rust-example-rendered"><code><spanclass="kw">use </span>educe::Educe;
<h6id="generic-parameters-bound-to-the-ord-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-ord-trait-or-others">§</a>Generic Parameters Bound to the <code>Ord</code> Trait or Others</h6>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(Hash)]</code> to implement the <code>Hash</code> trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the <code>Hash</code> trait.</p>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>Hash</code> trait for a field, eliminating the need to implement the <code>Hash</code> trait for the type of that field.</p>
<h6id="generic-parameters-bound-to-the-hash-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-hash-trait-or-others">§</a>Generic Parameters Bound to the <code>Hash</code> Trait or Others</h6>
<p>The <code>#[educe(PartialEq(unsafe), Eq, Hash(unsafe))]</code> attribute can be used for a union. The fields of a union cannot be hashed with other methods. The implementation is <strong>unsafe</strong> because it disregards the specific fields it utilizes.</p>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(Default)]</code> to implement the <code>Default</code> trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the <code>Hash</code> trait.</p>
<p>For enums and unions, it is necessary to designate a default variant (for enums) and a default field (for unions) unless the enum has only one variant or the union has only one field.</p>
<h6id="the-default-value-for-the-entire-type"><aclass="doc-anchor"href="#the-default-value-for-the-entire-type">§</a>The Default Value for the Entire Type</h6>
<h6id="the-default-values-for-specific-fields"><aclass="doc-anchor"href="#the-default-values-for-specific-fields">§</a>The Default Values for Specific Fields</h6>
<h6id="generic-parameters-bound-to-the-default-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-default-trait-or-others">§</a>Generic Parameters Bound to the <code>Default</code> Trait or Others</h6>
<p>With the <code>#[educe(Default(new))]</code> attribute, your type will include an additional associated function called <code>new</code>. This function can be utilized to invoke the <code>default</code> method of the <code>Default</code> trait.</p>
<p>Use <code>#[derive(Educe)]</code> and <code>#[educe(Into(type))]</code> to implement the <code>Into<type></code> trait for a struct or enum.</p>
<p>You need to designate a field as the default for <code>Into<type></code> conversion unless the number of fields is exactly one. If you don’t, educe will automatically try to find a proper one.</p>
<h6id="use-another-method-to-perform-into-conversion"><aclass="doc-anchor"href="#use-another-method-to-perform-into-conversion">§</a>Use Another Method to Perform Into Conversion</h6>
<p>The <code>method</code> parameter can be utilized to replace the implementation of the <code>Into</code> trait for a field, eliminating the need to implement the <code>Into</code> trait for the type of that field.</p>
<h6id="generic-parameters-bound-to-the-into-trait-or-others"><aclass="doc-anchor"href="#generic-parameters-bound-to-the-into-trait-or-others">§</a>Generic Parameters Bound to the <code>Into</code> Trait or Others</h6>