Skip to content

Commit ba920ab

Browse files
authored
Allow inserting non-Default values to VortexSession (#7321)
Previously there was no way to insert a non-default session var Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent 6f291c7 commit ba920ab

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

vortex-session/public-api.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ pub fn vortex_session::VortexSession::empty() -> Self
114114

115115
pub fn vortex_session::VortexSession::with<V: vortex_session::SessionVar + core::default::Default>(self) -> Self
116116

117+
pub fn vortex_session::VortexSession::with_some<V: vortex_session::SessionVar>(self, var: V) -> Self
118+
117119
impl core::clone::Clone for vortex_session::VortexSession
118120

119121
pub fn vortex_session::VortexSession::clone(&self) -> vortex_session::VortexSession

vortex-session/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ impl VortexSession {
3939
///
4040
/// If a variable of that type already exists.
4141
pub fn with<V: SessionVar + Default>(self) -> Self {
42+
self.with_some(V::default())
43+
}
44+
45+
/// Inserts a new session variable of type `V`.
46+
///
47+
/// # Panics
48+
///
49+
/// If a variable of that type already exists.
50+
pub fn with_some<V: SessionVar>(self, var: V) -> Self {
4251
match self.0.entry(TypeId::of::<V>()) {
4352
Entry::Occupied(_) => {
4453
vortex_panic!(
@@ -47,7 +56,7 @@ impl VortexSession {
4756
);
4857
}
4958
Entry::Vacant(e) => {
50-
e.insert(Box::new(V::default()));
59+
e.insert(Box::new(var));
5160
}
5261
}
5362
self

0 commit comments

Comments
 (0)