referrerpolicy=no-referrer-when-downgrade

Derive Macro frame_support::DefaultNoBound

source ·
#[derive(DefaultNoBound)]
{
    // Attributes available to this derive:
    #[default]
}
Expand description

Derive Default but do not bound any generic.

This is useful for type generic over runtime:

trait Config {
	type C: Default;
}

// Foo implements [`Default`] because `C` bounds [`Default`].
// Otherwise compilation will fail with an output telling `c` doesn't implement [`Default`].
#[derive(DefaultNoBound)]
struct Foo<T: Config> {
	c: T::C,
}

// Also works with enums, by specifying the default with #[default]:
#[derive(DefaultNoBound)]
enum Bar<T: Config> {
	// Bar will implement Default as long as all of the types within Baz also implement default.
	#[default]
	Baz(T::C),
	Quxx,
}

derive Default but do no bound any generic. Docs are at frame_support::DefaultNoBound.