summaryrefslogtreecommitdiffstats
path: root/vendor/zerofrom-derive/examples
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/zerofrom-derive/examples')
-rw-r--r--vendor/zerofrom-derive/examples/zf_derive.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/zerofrom-derive/examples/zf_derive.rs b/vendor/zerofrom-derive/examples/zf_derive.rs
index 4f54c9464..a1bde8373 100644
--- a/vendor/zerofrom-derive/examples/zf_derive.rs
+++ b/vendor/zerofrom-derive/examples/zf_derive.rs
@@ -86,4 +86,28 @@ pub enum CloningZF3<'data> {
Cow(#[zerofrom(clone)] Cow<'data, str>),
}
+#[derive(ZeroFrom)]
+#[zerofrom(may_borrow(T))] // instead of treating T as a copy type, we want to allow zerofromming T too
+pub struct GenericsThatAreAlsoZf<T> {
+ x: T,
+ y: Option<T>,
+}
+
+pub fn assert_zf_generics_may_borrow<'a, 'b>(
+ x: &'b GenericsThatAreAlsoZf<&'a str>,
+) -> GenericsThatAreAlsoZf<&'b str> {
+ GenericsThatAreAlsoZf::<&'b str>::zero_from(x)
+}
+
+#[derive(ZeroFrom)]
+pub struct UsesGenericsThatAreAlsoZf<'a> {
+ x: GenericsThatAreAlsoZf<&'a str>,
+}
+
+// Ensure it works with invariant types too
+#[derive(ZeroFrom)]
+pub struct UsesGenericsThatAreAlsoZfWithMap<'a> {
+ x: GenericsThatAreAlsoZf<ZeroMap<'a, str, str>>,
+}
+
fn main() {}