mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Name the erased repark and replay function types
This commit is contained in:
@@ -48,7 +48,7 @@ pub trait Attribute: 'static {
|
||||
|
||||
/// Re-parks the owned clone [`Self::read_erased`] produced into fresh
|
||||
/// field storage; `None` for plain values, which ride the byte copy.
|
||||
const REPARK: Option<unsafe fn(&dyn AnyAttributeValue, *mut u8, &crate::arena::Arena) -> Option<()>> = None;
|
||||
const REPARK: Option<crate::list::ReparkFn> = None;
|
||||
}
|
||||
|
||||
/// A kernel-facing attribute value. A parameter `Attr<A>` is a read of `A`
|
||||
|
||||
@@ -85,6 +85,12 @@ pub trait AnyAttributeValue: std::any::Any + Send + Sync {
|
||||
fn into_attribute(self: Box<Self>, key: &str, preceding_defaults: usize) -> Box<dyn AnyAttribute>;
|
||||
}
|
||||
|
||||
/// Re-parks an owned attribute value into fresh field storage; `None` reports arena exhaustion.
|
||||
pub type ReparkFn = unsafe fn(&dyn AnyAttributeValue, *mut u8, &crate::arena::Arena) -> Option<()>;
|
||||
|
||||
/// Replays an owned attribute value into a serving arena; `Some(None)` is unchanged, `None` reports arena exhaustion.
|
||||
pub type FieldReplayFn = fn(&dyn AnyAttributeValue, &crate::arena::Arena) -> Option<Option<Box<dyn AnyAttributeValue>>>;
|
||||
|
||||
impl<T: Clone + Send + Sync + Default + Sized + Debug + PartialEq + CacheHash + 'static> AnyAttributeValue for T {
|
||||
/// Clones this value into a new boxed trait object.
|
||||
fn clone_box(&self) -> Box<dyn AnyAttributeValue> {
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct FieldWrite {
|
||||
pub align: usize,
|
||||
pub type_id: std::any::TypeId,
|
||||
pub read_erased: unsafe fn(*const u8) -> Box<dyn crate::list::AnyAttributeValue>,
|
||||
pub repark: Option<unsafe fn(&dyn crate::list::AnyAttributeValue, *mut u8, &crate::arena::Arena) -> Option<()>>,
|
||||
pub repark: Option<crate::list::ReparkFn>,
|
||||
/// Hashes the field's content. `None` means the stored bytes are the
|
||||
/// content, which holds for every unparked value.
|
||||
pub content_hash: Option<unsafe fn(*const u8, &mut dyn core::hash::Hasher)>,
|
||||
@@ -64,7 +64,7 @@ pub struct FieldDesc {
|
||||
pub align: usize,
|
||||
pub type_id: std::any::TypeId,
|
||||
pub read_erased: unsafe fn(*const u8) -> Box<dyn crate::list::AnyAttributeValue>,
|
||||
pub repark: Option<unsafe fn(&dyn crate::list::AnyAttributeValue, *mut u8, &crate::arena::Arena) -> Option<()>>,
|
||||
pub repark: Option<crate::list::ReparkFn>,
|
||||
/// Hashes the field's content. `None` means the stored bytes are the
|
||||
/// content, which holds for every unparked value.
|
||||
pub content_hash: Option<unsafe fn(*const u8, &mut dyn core::hash::Hasher)>,
|
||||
|
||||
@@ -43,7 +43,7 @@ pub(in crate::record) fn deep_element_glue(type_id: std::any::TypeId) -> Option<
|
||||
#[derive(Clone, Copy)]
|
||||
pub(in crate::record) struct DeepFieldGlue {
|
||||
pub(in crate::record) copy_out: fn(&dyn crate::list::AnyAttributeValue) -> Option<Box<dyn crate::list::AnyAttributeValue>>,
|
||||
pub(in crate::record) replay: fn(&dyn crate::list::AnyAttributeValue, &crate::arena::Arena) -> Option<Option<Box<dyn crate::list::AnyAttributeValue>>>,
|
||||
pub(in crate::record) replay: crate::list::FieldReplayFn,
|
||||
}
|
||||
|
||||
static DEEP_FIELD_VALUES: std::sync::LazyLock<std::sync::Mutex<std::collections::HashMap<std::any::TypeId, DeepFieldGlue>>> = std::sync::LazyLock::new(Default::default);
|
||||
@@ -52,7 +52,7 @@ static DEEP_FIELD_VALUES: std::sync::LazyLock<std::sync::Mutex<std::collections:
|
||||
/// Called at startup from the crate that owns the type.
|
||||
pub fn register_deep_field_value<T: 'static>(
|
||||
copy_out: fn(&dyn crate::list::AnyAttributeValue) -> Option<Box<dyn crate::list::AnyAttributeValue>>,
|
||||
replay: fn(&dyn crate::list::AnyAttributeValue, &crate::arena::Arena) -> Option<Option<Box<dyn crate::list::AnyAttributeValue>>>,
|
||||
replay: crate::list::FieldReplayFn,
|
||||
) {
|
||||
DEEP_FIELD_VALUES.lock().unwrap().insert(std::any::TypeId::of::<T>(), DeepFieldGlue { copy_out, replay });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user