external-crates/move/crates/move-stdlib/docs/std/internal.md
<a name="std_internal"></a>
std::internalDefines the <code><a href="../std/internal.md#std_internal_Permit">Permit</a></code> type, which can be used to constrain the logic of a generic function to be authorized only by the module that defines the type parameter.
module example::use_permit;
public struct MyType { /* ... */ }
public fun test_permit() {
let permit = internal::permit<MyType>();
/* external_module::call_with_permit(permit); */
}
To write a function that is guarded by a <code><a href="../std/internal.md#std_internal_Permit">Permit</a></code>, require it as an argument.
// Silly mockup of a type registry where a type can be registered only by
// the module that defines the type.
module example::type_registry;
public fun register_type<T>(_: internal::Permit<T> /* ... */) {
/* ... */
}
<a name="std_internal_Permit"></a>
PermitA privileged witness of the <code>T</code> type. Instances can only be created by the module that defines the type <code>T</code>.
<pre><code><b>public</b> <b>struct</b> <a href="../std/internal.md#std_internal_Permit">Permit</a><<b>phantom</b> T> <b>has</b> drop </code></pre> <details> <summary>Fields</summary> <dl> </dl> </details><a name="std_internal_permit"></a>
permitConstruct a new <code><a href="../std/internal.md#std_internal_Permit">Permit</a></code> for the type <code>T</code>. Can only be called by the module that defines the type <code>T</code>.
<pre><code><b>public</b> <b>fun</b> <a href="../std/internal.md#std_internal_permit">permit</a><T>(): <a href="../std/internal.md#std_internal_Permit">std::internal::Permit</a><T> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="../std/internal.md#std_internal_permit">permit</a><T>(): <a href="../std/internal.md#std_internal_Permit">Permit</a><T> { <a href="../std/internal.md#std_internal_Permit">Permit</a>() } </code></pre> </details>