Skip to main content

CloneIntoContext

Derive Macro CloneIntoContext 

Source
#[derive(CloneIntoContext)]
Expand description

Implement CloneIntoContext for a struct or enum, assuming every field’s type already implements it. For an enum, the matched variant is reconstructed with its (cloned) fields.

Usage:

use pliron::{derive::CloneIntoContext, r#type::TypeHandle};

#[derive(CloneIntoContext)]
struct MyAttr {
    ty: TypeHandle,
    val: u64,
}

A generic struct, with the field’s bound written explicitly:

use pliron::{
    context::Context, derive::CloneIntoContext,
    irbuild::decontext::CloneIntoContext as CloneIntoContextTrait,
};

#[derive(CloneIntoContext)]
struct Wrapper<T: CloneIntoContextTrait> {
    inner: T,
}

let src_ctx = Context::new();
let mut dst_ctx = Context::new();
let cloned = Wrapper { inner: 42u64 }.clone_into_context(&src_ctx, &mut dst_ctx);
assert_eq!(cloned.inner, 42);

This fails to compile because NotCloneable doesn’t implement CloneIntoContext:

use pliron::derive::CloneIntoContext;

struct NotCloneable;

#[derive(CloneIntoContext)]
struct MyAttr {
    val: NotCloneable,
}