Skip to main content

New

Trait New 

Source
pub trait New {
    // Required method
    fn new() -> Self;
}
Expand description

This trait is a generalization of Default::default. The difference is that some types may provide a constructor with no arguments, but not implement Default for some reason. That might be that it’s expensive to create, or mutates some global state, or does some IO, etc.

Every type implementing Default gets a New instance.

Required Methods§

Source

fn new() -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Default> New for T