pub trait TryUpdateFrom<T> {
    type Error;

    // Required methods
    fn check_try_update_from(&self, value: &T) -> Result<(), Self::Error>;
    unsafe fn update_from_unchecked(&mut self, value: T);

    // Provided method
    fn try_update_from(&mut self, value: T) -> Result<(), Self::Error> { ... }
}
Expand description

A trait, that updates internal state of a type using an instance of another type.

Required Associated Types§

source

type Error

Error, that may be thrown during update.

Required Methods§

source

fn check_try_update_from(&self, value: &T) -> Result<(), Self::Error>

Checks, that update is possible.

Returns Self::Error, when update is impossible.

source

unsafe fn update_from_unchecked(&mut self, value: T)

Performs the update without checking, whether update is possible.

This method should not be used directly. Use Self::try_update_from instead.

§Panics

This method should panic, when update is not possible. It is marked as unsafe since Rust type system can’t guarantee, that the contract will be fulfilled by implementor.

Provided Methods§

source

fn try_update_from(&mut self, value: T) -> Result<(), Self::Error>

Performs the update.

If you are going to reimplement the blanket implementation, then it is mandatory, that all checks related to the possibility of update should be performed before the update.

Returns Self::Error, when update is impossible.

Implementors§