From 3d59ffffefaf9082da32a1827b85ee59af13cf34 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 8 Feb 2024 20:37:32 -0800 Subject: [PATCH] Utility method --- crates/content/src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/content/src/lib.rs b/crates/content/src/lib.rs index 46598b8..70becbf 100644 --- a/crates/content/src/lib.rs +++ b/crates/content/src/lib.rs @@ -12,6 +12,7 @@ use rhai::ImmutableString; use serde::{Deserialize, Deserializer}; use smartstring::{LazyCompact, SmartString}; use std::{ + borrow::Borrow, collections::HashMap, fmt::Display, fs::File, @@ -130,7 +131,20 @@ pub struct ContentIndex(Arc>); impl From for ContentIndex { fn from(value: ImmutableString) -> Self { - Self::new(&value) + Self(Arc::new(value.into())) + } +} + +impl From for ImmutableString { + fn from(value: ContentIndex) -> Self { + ImmutableString::from(Arc::into_inner(value.0).unwrap()) + } +} + +impl From<&ContentIndex> for ImmutableString { + fn from(value: &ContentIndex) -> Self { + let x: &SmartString = value.0.borrow(); + ImmutableString::from(x.clone()) } }