From 3f568f39902154adb7c4bfbc6b704c323e9e21c1 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 31 May 2022 18:59:40 +0100 Subject: [PATCH] Simplify session conversion to database context --- lib/src/dbs/session.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/src/dbs/session.rs b/lib/src/dbs/session.rs index 7c119387..6d217d59 100644 --- a/lib/src/dbs/session.rs +++ b/lib/src/dbs/session.rs @@ -35,10 +35,6 @@ impl Session { } // Convert a session into a runtime pub(crate) fn context<'a>(&self, mut ctx: Context<'a>) -> Context<'a> { - // Add session value - let key = String::from("session"); - let val: Value = self.into(); - ctx.add_value(key, val); // Add scope value let key = String::from("scope"); let val: Value = self.sc.to_owned().into(); @@ -47,20 +43,18 @@ impl Session { let key = String::from("auth"); let val: Value = self.sd.to_owned().into(); ctx.add_value(key, val); + // Add session value + let key = String::from("session"); + let val: Value = Value::from(map! { + "ip".to_string() => self.ip.to_owned().into(), + "or".to_string() => self.or.to_owned().into(), + "id".to_string() => self.id.to_owned().into(), + "ns".to_string() => self.ns.to_owned().into(), + "db".to_string() => self.db.to_owned().into(), + "sc".to_string() => self.sc.to_owned().into(), + }); + ctx.add_value(key, val); // Output context ctx } } - -impl From<&Session> for Value { - fn from(val: &Session) -> Value { - Value::from(map! { - "ip".to_string() => val.ip.to_owned().into(), - "or".to_string() => val.or.to_owned().into(), - "id".to_string() => val.id.to_owned().into(), - "ns".to_string() => val.ns.to_owned().into(), - "db".to_string() => val.db.to_owned().into(), - "sc".to_string() => val.sc.to_owned().into(), - }) - } -}