Module std::internal
Defines the
Permit 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
Permit, 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> /* ... */) {
/* ... */
}
Struct Permit
A privileged witness of the T type.
Instances can only be created by the module that defines the type T.
public struct Permit<phantom T> has drop
Click to open
Fields
Function permit
Construct a new
Permit for the type T.
Can only be called by the module that defines the type T.
public fun permit<T>(): std::internal::Permit<T>