pub trait ConfigLoaderTrait<S, T, D> {
type RetType;
type Error;
// Required method
fn make_from(
config: &mut S,
cfg: T,
data: D,
) -> Result<Self::RetType, Self::Error>;
}
Expand description
A trait which is implemented by the structures which are planned to translate the
configuration structures into pre-prepared instances. For example, there is a
CfgServer which is deserialized from the /etc/myprogram/server.shm
which contains generic
fields like bind address encoded as String and may contain errors. A structure
ConfigServer which parses this data to IpAddr instance. It implements this trait in order to
be attached to CfgServer
and called to fill its fields from CfgServer
.
Required Associated Types§
Required Methods§
Sourcefn make_from(
config: &mut S,
cfg: T,
data: D,
) -> Result<Self::RetType, Self::Error>
fn make_from( config: &mut S, cfg: T, data: D, ) -> Result<Self::RetType, Self::Error>
This function is called to build a ‘Self::RetType’ as a result.
The following generics should be provided:
-
S
- an instance which can be reused to open another file. Usually a structure which holds the ConfigLoader instance. -
T
- a structure which holds the deserialized config file to be processed. -
D
- an additional arguments to be passed to next. Usually it is()
when there is nothing to pass. However, it it is required to pass something to the next stage, this generic argument can be used.
§Returns
A Result is returned with the:
-
[Result::Ok()] is returned with inner type
Self::RetType
which describes the result. -
[Result::Err()] is returned with the error description.
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.