-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathsession.rs
More file actions
65 lines (52 loc) · 1.65 KB
/
session.rs
File metadata and controls
65 lines (52 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Module for managing extension dtypes in a Vortex session.
use std::sync::Arc;
use vortex_session::Ref;
use vortex_session::SessionExt;
use vortex_session::registry::Registry;
use crate::dtype::extension::ExtDTypePluginRef;
use crate::dtype::extension::ExtVTable;
use crate::extension::datetime::Date;
use crate::extension::datetime::Time;
use crate::extension::datetime::Timestamp;
/// Registry for extension dtypes.
pub type ExtDTypeRegistry = Registry<ExtDTypePluginRef>;
/// Session for managing extension dtypes.
#[derive(Debug)]
pub struct DTypeSession {
registry: ExtDTypeRegistry,
}
impl Default for DTypeSession {
fn default() -> Self {
let this = Self {
registry: Registry::default(),
};
// Register built-in temporal extension dtypes
this.register(Date);
this.register(Time);
this.register(Timestamp);
this
}
}
impl DTypeSession {
/// Register an extension DType with the Vortex session.
pub fn register<V: ExtVTable>(&self, vtable: V) {
self.registry
.register(vtable.id(), Arc::new(vtable) as ExtDTypePluginRef);
}
/// Return the registry of extension dtypes.
pub fn registry(&self) -> &ExtDTypeRegistry {
&self.registry
}
}
/// Extension trait for accessing the DType session.
pub trait DTypeSessionExt: SessionExt {
/// Get the DType session.
fn dtypes(&self) -> Ref<'_, DTypeSession>;
}
impl<S: SessionExt> DTypeSessionExt for S {
fn dtypes(&self) -> Ref<'_, DTypeSession> {
self.get::<DTypeSession>()
}
}