26 lines
572 B
Rust
26 lines
572 B
Rust
use magnetar_calckey_model::ck;
|
|
use std::sync::Arc;
|
|
|
|
pub mod data;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct PackingContext {
|
|
instance_info: Arc<ck::meta::Model>,
|
|
self_user: Option<Arc<ck::user::Model>>,
|
|
}
|
|
|
|
pub trait PackType<I>: 'static {
|
|
fn extract(context: &PackingContext, data: I) -> Self;
|
|
}
|
|
|
|
impl PackingContext {
|
|
fn self_user(&self) -> Option<&ck::user::Model> {
|
|
self.self_user.as_deref()
|
|
}
|
|
|
|
fn is_self(&self, user: &ck::user::Model) -> bool {
|
|
self.self_user()
|
|
.is_some_and(|self_user| self_user.id == user.id)
|
|
}
|
|
}
|