Utility method

master
Mark 2024-02-08 20:37:32 -08:00
parent a67b7e89fc
commit 3d59ffffef
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 15 additions and 1 deletions

View File

@ -12,6 +12,7 @@ use rhai::ImmutableString;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use std::{ use std::{
borrow::Borrow,
collections::HashMap, collections::HashMap,
fmt::Display, fmt::Display,
fs::File, fs::File,
@ -130,7 +131,20 @@ pub struct ContentIndex(Arc<SmartString<LazyCompact>>);
impl From<ImmutableString> for ContentIndex { impl From<ImmutableString> for ContentIndex {
fn from(value: ImmutableString) -> Self { fn from(value: ImmutableString) -> Self {
Self::new(&value) Self(Arc::new(value.into()))
}
}
impl From<ContentIndex> 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<LazyCompact> = value.0.borrow();
ImmutableString::from(x.clone())
} }
} }