pub trait DefensiveTruncateFrom<T> {
// Required method
fn defensive_truncate_from(unbound: T) -> Self;
}
Expand description
Construct an object by defensively truncating an input if the TryFrom
conversion fails.
Required Methods§
fn defensive_truncate_from(unbound: T) -> Self
fn defensive_truncate_from(unbound: T) -> Self
Use TryFrom
first and defensively fall back to truncating otherwise.
§Example
use frame_support::{BoundedVec, traits::DefensiveTruncateFrom};
use sp_runtime::traits::ConstU32;
let unbound = vec![1, 2];
let bound = BoundedVec::<u8, ConstU32<2>>::defensive_truncate_from(unbound);
assert_eq!(bound, vec![1, 2]);
Object Safety§
This trait is not object safe.