use std::borrow::Cow;
use std::marker::PhantomData;
use dizzy::DstNewtype;
#[derive(DstNewtype)]
#[dizzy(invariant = dizzy::trivial, error = std::convert::Infallible)]
#[dizzy(constructor = const new)]
#[dizzy(owned = StrBuf(String))]
#[dizzy(derive(Debug))]
#[dizzy(derive_owned(Debug))]
#[repr(transparent)]
struct Str<'a, 'b, T, U = ()> {
__data: PhantomData<(T, U, &'a (), &'b ())>,
inner: str,
}
#[test]
fn cow_from_owned() {
let s: &Str<'_, '_, ()> = Str::new("hello").unwrap();
let buf: StrBuf<'_, '_, ()> = s.to_owned();
let cow: Cow<'_, Str<'_, '_, ()>> = Cow::from(&buf);
assert!(matches!(cow, Cow::Owned(_)));
}
#[test]
fn debug_impls_are_equivalent() {
let s: &Str<'_, '_, ()> = Str::new("hello").unwrap();
let buf: StrBuf<'_, '_, ()> = s.to_owned();
assert_eq!(format!("{s:?}"), format!("{buf:?}"));
}