mirror of https://github.com/zkat/miette.git
feat(source): Remove bound `T: Clone` from `Source` implementation for `Cow`. (#42)
This change removes the bound `T: Clone` in the implementation of `Source` for `Cow<'_, T>`. This expands the implementation of `Source` to include types like `Cow<'_, str>`. Importantly, `Cow` always requires the bound `T: ToOwned` and uses `ToOwned` to implement `Clone` rather than forwarding to `T::clone`.
This commit is contained in:
parent
84219f6c80
commit
0427c9f966
|
|
@ -1,7 +1,11 @@
|
|||
/*!
|
||||
Default trait implementations for [Source].
|
||||
*/
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
use std::{
|
||||
borrow::{Cow, ToOwned},
|
||||
fmt::Debug,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use crate::{MietteError, MietteSpanContents, Source, SourceSpan, SpanContents};
|
||||
|
||||
|
|
@ -84,7 +88,12 @@ impl<T: Source> Source for Arc<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Source + Clone> Source for Cow<'_, T> {
|
||||
impl<T: ?Sized + Source + ToOwned> Source for Cow<'_, T>
|
||||
where
|
||||
// The minimal bounds are used here. `T::Owned` need not be `Source`, because `&T` can always
|
||||
// be obtained from `Cow<'_, T>`.
|
||||
T::Owned: Debug + Send + Sync,
|
||||
{
|
||||
fn read_span<'a>(
|
||||
&'a self,
|
||||
span: &SourceSpan,
|
||||
|
|
|
|||
Loading…
Reference in New Issue