Functions such as boxup or from_isolang explicitly use dyn Language. The generic Language for Box<L> implementation isn’t actually problematic if Language isn’t object safe anymore.
I’m not entirely sure if you’re trying to keep using dyn Language i.e. keep Language object safe or not. If you do want to keep object safety, then the : Clone supertrait is not an option. One possible alternative is to use something like the dyn_clone crate.
the parameter type L may not live long enough
...so that the type L will meet its required lifetime bounds
What I'm trying to do is wrap a DynamicFormatter from Formatter. The timeago crate Formatter structure is parameterized with a Language, so for my needs I need a version of this structure that is not parameterized (constructed with a runtime Language).
The error above is on following code (timeago fork):
impl<L: Language> Formatter<L> {
/// Constructor for some default formatting with specified language instance
///
/// It emits one item (chunk), limits to seconds and has no maximum duration.
pub fn with_language(l: L) -> Self {
Formatter {
lang: dyn_clone::clone(&l),
_subformatter: DynamicFormatter::with_language(dyn_clone::clone_box(&l)),
}
}
(Error is on _subformatter field's value).
I'd like to not break compatibility with this timeago fork. Appreciate further help!
The type Box<dyn Language>, or more explicitly and equivalently Box<dyn Language + 'static>, can only be created from a type Box<L> if there is a L: 'static bound.
I think the easiest way to fix your problem is to just add a where clause where L: 'static to pub fn with_language. This does create some limitation on the types that can be used for L (e. g. limiting the usability of reference types in place of L), but AFAICT this should not matter at all for the kinds of types that implement the Language trait.