Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

In Rust, it is no possible to define default values in methods and functions. This implies that in a constructor method we cannot make optional the setting of certain fields. To be able to set default values to fields and still allow the user to easily set his/her own values while building a new object, we need another mechanism called Builder Setters. The convention in Rust is to name those methods using the with_ prefix. The idea is to chain one more with_...() methods after the call to the constructor new(). Each method takes ownership of the object, modifies it and returns it.

Example:

see solution